logging: backend: Migrate to the new Common::FS library

This commit is contained in:
Morph
2022-10-31 20:57:49 +02:00
committed by GPUCode
parent 97cbcc6e49
commit c02b0a0113
2 changed files with 11 additions and 14 deletions

View File

@ -12,10 +12,7 @@
#include <thread> #include <thread>
#include <vector> #include <vector>
#ifdef _WIN32 #ifdef _WIN32
#include <share.h> // For _SH_DENYWR
#include <windows.h> // For OutputDebugStringW #include <windows.h> // For OutputDebugStringW
#else
#define _SH_DENYWR 0
#endif #endif
#include "common/assert.h" #include "common/assert.h"
#include "common/fs/fs.h" #include "common/fs/fs.h"
@ -145,17 +142,16 @@ void LogcatBackend::Write(const Entry& entry) {
PrintMessageToLogcat(entry); PrintMessageToLogcat(entry);
} }
FileBackend::FileBackend(const std::string& filename) : bytes_written(0) { FileBackend::FileBackend(const std::filesystem::path& filename) : bytes_written(0) {
if (Common::FS::Exists(filename + ".old.txt")) { auto old_filename = filename;
Common::FS::RemoveFile(filename + ".old.txt"); old_filename += ".old.txt";
}
if (Common::FS::Exists(filename)) {
Common::FS::RenameFile(filename, filename + ".old.txt");
}
// _SH_DENYWR allows read only access to the file for other programs. // Existence checks are done within the functions themselves.
// It is #defined to 0 on other platforms // We don't particularly care if these succeed or not.
file = Common::FS::IOFile(filename, "w", _SH_DENYWR); static_cast<void>(Common::FS::RemoveFile(old_filename));
static_cast<void>(Common::FS::RenameFile(filename, old_filename));
file = Common::FS::IOFile(filename, Common::FS::FileAccessMode::Write, Common::FS::FileType::TextFile);
} }
void FileBackend::Write(const Entry& entry) { void FileBackend::Write(const Entry& entry) {

View File

@ -5,6 +5,7 @@
#pragma once #pragma once
#include <chrono> #include <chrono>
#include <filesystem>
#include <memory> #include <memory>
#include <string> #include <string>
#include <string_view> #include <string_view>
@ -100,7 +101,7 @@ public:
*/ */
class FileBackend : public Backend { class FileBackend : public Backend {
public: public:
explicit FileBackend(const std::string& filename); explicit FileBackend(const std::filesystem::path& filename);
static const char* Name() { static const char* Name() {
return "file"; return "file";