MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ rotate_file()

bool MayaFlux::IO::TextFileWriter::rotate_file ( )
private

Definition at line 181 of file TextFileWriter.cpp.

182{
183 m_file.flush();
184 m_file.close();
185
186 auto now = std::chrono::system_clock::now();
187 auto time_t = std::chrono::system_clock::to_time_t(now);
188
189 std::ostringstream oss;
190 oss << m_filepath << "."
191 << std::put_time(std::localtime(&time_t), "%Y%m%d_%H%M%S");
192
193 std::string backup_path = oss.str();
194
195 try {
196 std::filesystem::rename(m_filepath, backup_path);
197 } catch (const std::filesystem::filesystem_error& e) {
198 m_last_error = std::string("Failed to rotate file: ") + e.what();
199 return false;
200 }
201
202 std::ios_base::openmode mode = std::ios_base::out | std::ios_base::trunc;
203 m_file.open(m_filepath, mode);
204
205 if (!m_file.is_open()) {
206 m_last_error = "Failed to reopen file after rotation";
207 return false;
208 }
209
210 m_bytes_written = 0;
211 return true;
212}

References m_bytes_written, m_file, m_filepath, and m_last_error.

Referenced by write_bytes().

+ Here is the caller graph for this function: