diff --git a/Sts1CobcSw/FileSystem/LfsWrapper.cpp b/Sts1CobcSw/FileSystem/LfsWrapper.cpp index fbf545bc..fc59cd06 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(); + } + + // dont 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..7bf1d643 100644 --- a/Sts1CobcSw/FileSystem/LfsWrapper.hpp +++ b/Sts1CobcSw/FileSystem/LfsWrapper.hpp @@ -50,7 +50,7 @@ class File // Only allow creation of File class through friend function Open() 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;