diff options
author | drbasic <drbasic@yandex-team.com> | 2024-08-05 09:10:03 +0300 |
---|---|---|
committer | drbasic <drbasic@yandex-team.com> | 2024-08-05 09:21:20 +0300 |
commit | 95f0248d5a766eac88212c429966702dec272773 (patch) | |
tree | 25727027a903350aa43b91356bd7de16df8893c1 | |
parent | feaa798c9e6b0df5535f86d2ccc7c9f8d007ceda (diff) | |
download | ydb-95f0248d5a766eac88212c429966702dec272773.tar.gz |
Add missed move assignment for TFileHandle
3fbccc0ac152bfb68fd6ce1ede5a383ab34cce0c
-rw-r--r-- | util/system/file.h | 8 | ||||
-rw-r--r-- | util/system/file_ut.cpp | 24 |
2 files changed, 31 insertions, 1 deletions
diff --git a/util/system/file.h b/util/system/file.h index bf5791271d..57531fd8c9 100644 --- a/util/system/file.h +++ b/util/system/file.h @@ -61,7 +61,7 @@ enum SeekDir { sEnd = 2, }; -class TFileHandle: public TNonCopyable { +class TFileHandle: TMoveOnly { public: constexpr TFileHandle() = default; @@ -85,6 +85,12 @@ public: Close(); } + TFileHandle& operator=(TFileHandle&& other) noexcept { + Close(); + Fd_ = other.Release(); + return *this; + } + bool Close() noexcept; inline FHANDLE Release() noexcept { diff --git a/util/system/file_ut.cpp b/util/system/file_ut.cpp index 941e6a50f3..2ee455411c 100644 --- a/util/system/file_ut.cpp +++ b/util/system/file_ut.cpp @@ -405,6 +405,30 @@ UNIT_ASSERT_VALUES_EQUAL(file.CountCache(0, 12345), -1); #endif } +Y_UNIT_TEST_SUITE(TTestFileHandle) { + Y_UNIT_TEST(MoveAssignment) { + TTempFile tmp("tmp"); + { + TFileHandle file1(tmp.Name(), OpenAlways | WrOnly); + file1.Write("1", 1); + + TFileHandle file2; + file2 = std::move(file1); + Y_ENSURE(!file1.IsOpen()); + Y_ENSURE(file2.IsOpen()); + + file2.Write("2", 1); + } + + { + TFileHandle file(tmp.Name(), OpenExisting | RdOnly); + char buf[2]; + Y_ENSURE(file.Read(buf, 2) == 2); + Y_ENSURE(TStringBuf(buf, 2) == "12"); + } + } +} + Y_UNIT_TEST_SUITE(TTestDecodeOpenMode) { Y_UNIT_TEST(It) { UNIT_ASSERT_VALUES_EQUAL("0", DecodeOpenMode(0)); |