diff --git a/src/common/file_system.cpp b/src/common/file_system.cpp index 364199b26..6184a231a 100644 --- a/src/common/file_system.cpp +++ b/src/common/file_system.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #ifdef __APPLE__ #include @@ -2823,6 +2824,10 @@ static bool SetLock(int fd, bool lock) return res; } +FileSystem::POSIXLock::POSIXLock() : m_fd(-1) +{ +} + FileSystem::POSIXLock::POSIXLock(int fd) : m_fd(fd) { if (!SetLock(m_fd, true)) @@ -2835,10 +2840,21 @@ FileSystem::POSIXLock::POSIXLock(std::FILE* fp) : m_fd(fileno(fp)) m_fd = -1; } +FileSystem::POSIXLock::POSIXLock(POSIXLock&& move) +{ + m_fd = std::exchange(move.m_fd, -1); +} + FileSystem::POSIXLock::~POSIXLock() { if (m_fd >= 0) SetLock(m_fd, false); } +FileSystem::POSIXLock& FileSystem::POSIXLock::operator=(POSIXLock&& move) +{ + m_fd = std::exchange(move.m_fd, -1); + return *this; +} + #endif diff --git a/src/common/file_system.h b/src/common/file_system.h index 7003001ea..5b816ce1d 100644 --- a/src/common/file_system.h +++ b/src/common/file_system.h @@ -159,10 +159,16 @@ void DiscardAtomicRenamedFile(AtomicRenamedFile& file); class POSIXLock { public: + POSIXLock(); POSIXLock(int fd); POSIXLock(std::FILE* fp); + POSIXLock(POSIXLock&& move); + POSIXLock(const POSIXLock&) = delete; ~POSIXLock(); + POSIXLock& operator=(POSIXLock&& move); + POSIXLock& operator=(const POSIXLock&) = delete; + private: int m_fd; };