Skip to content

Commit 9d871c2

Browse files
committed
FDS output: add .tmp suffix for files in progress
1 parent 6a5f768 commit 9d871c2

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/plugins/output/fds/src/Storage.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,20 @@ Storage::Storage(ipx_ctx_t *ctx, const Config &cfg) : m_ctx(ctx), m_path(cfg.m_p
4646
m_flags |= FDS_FILE_APPEND;
4747
}
4848

49+
Storage::~Storage()
50+
{
51+
window_close();
52+
}
53+
4954
void
5055
Storage::window_new(time_t ts)
5156
{
5257
// Close the current window if exists
5358
window_close();
5459

5560
// Open new file
56-
const std::string new_file = filename_gen(ts);
61+
const std::string new_file = filename_gen(ts) + ".tmp";
62+
m_file_name = new_file;
5763
std::unique_ptr<char, decltype(&free)> new_file_cpy(strdup(new_file.c_str()), &free);
5864

5965
char *dir2create;
@@ -82,6 +88,11 @@ Storage::window_close()
8288
{
8389
m_file.reset();
8490
m_session2params.clear();
91+
if (!m_file_name.empty()) {
92+
std::string new_file_name(m_file_name.begin(), m_file_name.end() - std::string(".tmp").size());
93+
std::rename(m_file_name.c_str(), new_file_name.c_str());
94+
m_file_name.clear();
95+
}
8596
}
8697

8798
void

src/plugins/output/fds/src/Storage.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Storage {
3636
* @throw FDS_exception if @p path directory doesn't exist in the system
3737
*/
3838
Storage(ipx_ctx_t *ctx, const Config &cfg);
39-
virtual ~Storage() = default;
39+
virtual ~Storage();
4040

4141
// Disable copy constructors
4242
Storage(const Storage &other) = delete;
@@ -105,6 +105,8 @@ class Storage {
105105

106106
/// Output FDS file
107107
std::unique_ptr<fds_file_t, decltype(&fds_file_close)> m_file = {nullptr, &fds_file_close};
108+
/// Output FDS file name
109+
std::string m_file_name;
108110
/// Mapping of Transport Sessions to FDS specific parameters
109111
std::map<const struct ipx_session *, struct session_ctx> m_session2params;
110112

0 commit comments

Comments
 (0)