diff options
| author | 2017-05-22 13:23:49 +0100 | |
|---|---|---|
| committer | 2017-05-22 13:23:49 +0100 | |
| commit | eda7d3d7ea48a6ab6bb6ad007b14a10e1a9896cd (patch) | |
| tree | 51bfea953b08cf7313e579797625672d525709fa | |
| parent | 95c7d5b995a975723113a2ef38befb86e4bfbf45 (diff) | |
FdFile: fix operator=(FdFile&&)
We need to copy the read_only_mode_ flag as well.
Test: fd_file_test
Change-Id: I5b66fcefb30affa36c33d3633df3be19fef1f7f7
| -rw-r--r-- | runtime/base/unix_file/fd_file.cc | 1 | ||||
| -rw-r--r-- | runtime/base/unix_file/fd_file_test.cc | 14 |
2 files changed, 15 insertions, 0 deletions
diff --git a/runtime/base/unix_file/fd_file.cc b/runtime/base/unix_file/fd_file.cc index 03fc959f6b..00b5567012 100644 --- a/runtime/base/unix_file/fd_file.cc +++ b/runtime/base/unix_file/fd_file.cc @@ -91,6 +91,7 @@ FdFile& FdFile::operator=(FdFile&& other) { fd_ = other.fd_; file_path_ = std::move(other.file_path_); auto_close_ = other.auto_close_; + read_only_mode_ = other.read_only_mode_; other.Release(); // Release other. return *this; diff --git a/runtime/base/unix_file/fd_file_test.cc b/runtime/base/unix_file/fd_file_test.cc index 7657a38cec..6aef348433 100644 --- a/runtime/base/unix_file/fd_file_test.cc +++ b/runtime/base/unix_file/fd_file_test.cc @@ -186,6 +186,20 @@ TEST_F(FdFileTest, MoveConstructor) { ASSERT_EQ(file2.Close(), 0); } +TEST_F(FdFileTest, OperatorMoveEquals) { + // Make sure the read_only_ flag is correctly copied + // over. + art::ScratchFile tmp; + FdFile file(tmp.GetFilename(), O_RDONLY, false); + ASSERT_TRUE(file.ReadOnlyMode()); + + FdFile file2(tmp.GetFilename(), O_RDWR, false); + ASSERT_FALSE(file2.ReadOnlyMode()); + + file2 = std::move(file); + ASSERT_TRUE(file2.ReadOnlyMode()); +} + TEST_F(FdFileTest, EraseWithPathUnlinks) { // New scratch file, zero-length. art::ScratchFile tmp; |