@@ -47,6 +47,19 @@ std::string strip_parent_path(const std::string & relative_path)
47
47
{
48
48
return fs::path (relative_path).filename ().generic_string ();
49
49
}
50
+
51
+ std::string remove_active_from_filename (const std::string& relative_path)
52
+ {
53
+ fs::path path (relative_path);
54
+ auto filename = path.filename ().string ();
55
+ auto active_pos = filename.find (" .active" );
56
+ if (active_pos != std::string::npos) {
57
+ filename.replace (active_pos, 7 , " " );
58
+ }
59
+ auto new_path = path.parent_path () / filename;
60
+ return new_path.string ();
61
+ }
62
+
50
63
} // namespace
51
64
52
65
SequentialWriter::SequentialWriter (
@@ -190,7 +203,11 @@ void SequentialWriter::close()
190
203
}
191
204
192
205
if (storage_) {
206
+ // when the storage_ is closed, rename the file to remove ".active" suffix
207
+ std::string active_path = storage_->get_relative_file_path ();
208
+ std::string final_path = remove_active_from_filename (active_path);
193
209
storage_.reset (); // Destroy storage before calling WRITE_SPLIT callback to make sure that
210
+ fs::rename (active_path, final_path);
194
211
// bag file was closed before callback call.
195
212
}
196
213
if (!metadata_.relative_file_paths .empty ()) {
@@ -309,7 +326,7 @@ std::string SequentialWriter::format_storage_uri(
309
326
// SequentialWriter is opened with a relative path.
310
327
std::stringstream storage_file_name;
311
328
storage_file_name << fs::path (base_folder).filename ().generic_string () << " _" <<
312
- storage_count;
329
+ storage_count << " .active " ;
313
330
314
331
return (fs::path (base_folder) / storage_file_name.str ()).generic_string ();
315
332
}
@@ -326,7 +343,15 @@ void SequentialWriter::switch_to_next_storage()
326
343
storage_options_.uri = format_storage_uri (
327
344
base_folder_,
328
345
metadata_.relative_file_paths .size ());
346
+
347
+ // when the storage_ is closed, rename the file to remove ".inactive" suffix
348
+ std::string active_path = storage_->get_relative_file_path ();
349
+ std::string final_path = remove_active_from_filename (active_path);
350
+
329
351
storage_ = storage_factory_->open_read_write (storage_options_);
352
+
353
+ std::filesystem::rename (active_path, final_path);
354
+
330
355
if (!storage_) {
331
356
std::stringstream errmsg;
332
357
errmsg << " Failed to rollover bagfile to new file: \" " << storage_options_.uri << " \" !" ;
0 commit comments