From 1624f4bffc5b1ee78e078f8d160f15ec3ca6f8cd Mon Sep 17 00:00:00 2001 From: Florian Donauer Date: Tue, 8 Oct 2024 08:49:37 +0000 Subject: [PATCH] Add closeAndKeepLockFile for LfsWrapper --- Sts1CobcSw/FileSystem/LfsWrapper.cpp | 22 ++++++++++++++++++++-- Sts1CobcSw/FileSystem/LfsWrapper.hpp | 1 + 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Sts1CobcSw/FileSystem/LfsWrapper.cpp b/Sts1CobcSw/FileSystem/LfsWrapper.cpp index fbf545bc..a185fb97 100644 --- a/Sts1CobcSw/FileSystem/LfsWrapper.cpp +++ b/Sts1CobcSw/FileSystem/LfsWrapper.cpp @@ -153,12 +153,30 @@ auto File::MoveConstructFrom(File * other) noexcept -> void openFlags_ = other->openFlags_; isOpen_ = true; } - (void)other->Close(); + (void)other->CloseAndKeepLockFile(); other->path_ = ""; other->lockFilePath_ = ""; other->openFlags_ = 0; other->lfsFile_ = {}; - (void)CreateLockFile(); // TODO handle lock file error +} + + +auto File::CloseAndKeepLockFile() -> Result +{ + if(not isOpen_) + { + return outcome_v2::success(); + } + + // don't remove lock file here + + auto error = lfs_file_close(&lfs, &lfsFile_); + if(error != 0) + { + return static_cast(error); + } + isOpen_ = false; + return outcome_v2::success(); } diff --git a/Sts1CobcSw/FileSystem/LfsWrapper.hpp b/Sts1CobcSw/FileSystem/LfsWrapper.hpp index 14a860ac..e4b05811 100644 --- a/Sts1CobcSw/FileSystem/LfsWrapper.hpp +++ b/Sts1CobcSw/FileSystem/LfsWrapper.hpp @@ -51,6 +51,7 @@ class File File() = default; auto MoveConstructFrom(File * other) noexcept -> void; [[nodiscard]] auto CreateLockFile() noexcept -> Result; + [[nodiscard]] auto CloseAndKeepLockFile() -> Result; [[nodiscard]] auto Read(void * buffer, std::size_t size) const -> Result; [[nodiscard]] auto Write(void const * buffer, std::size_t size) -> Result;