Skip to content

Commit 6c0a579

Browse files
authored
Merge pull request #61 from CESNET/sedlak-fds-output-tmp-suffix
Sedlak fds output tmp suffix
2 parents 6a5f768 + bda12ef commit 6c0a579

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include <libgen.h>
1818
#include "Storage.hpp"
1919

20+
const std::string TMP_SUFFIX = ".tmp";
21+
2022
Storage::Storage(ipx_ctx_t *ctx, const Config &cfg) : m_ctx(ctx), m_path(cfg.m_path)
2123
{
2224
// Check if the directory exists
@@ -46,14 +48,20 @@ Storage::Storage(ipx_ctx_t *ctx, const Config &cfg) : m_ctx(ctx), m_path(cfg.m_p
4648
m_flags |= FDS_FILE_APPEND;
4749
}
4850

51+
Storage::~Storage()
52+
{
53+
window_close();
54+
}
55+
4956
void
5057
Storage::window_new(time_t ts)
5158
{
5259
// Close the current window if exists
5360
window_close();
5461

5562
// Open new file
56-
const std::string new_file = filename_gen(ts);
63+
const std::string new_file = filename_gen(ts) + TMP_SUFFIX;
64+
m_file_name = new_file;
5765
std::unique_ptr<char, decltype(&free)> new_file_cpy(strdup(new_file.c_str()), &free);
5866

5967
char *dir2create;
@@ -80,8 +88,14 @@ Storage::window_new(time_t ts)
8088
void
8189
Storage::window_close()
8290
{
91+
bool file_opened = (m_file.get() != nullptr);
8392
m_file.reset();
8493
m_session2params.clear();
94+
if (file_opened) {
95+
std::string new_file_name(m_file_name.begin(), m_file_name.end() - TMP_SUFFIX.size());
96+
std::rename(m_file_name.c_str(), new_file_name.c_str());
97+
m_file_name.clear();
98+
}
8599
}
86100

87101
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)