From ab3728508f021757c0ebe2a1285b0c74d220d74c Mon Sep 17 00:00:00 2001 From: Ayush Ranjan Date: Wed, 16 Feb 2022 19:25:35 -0800 Subject: [PATCH] Add syscall test for rename when an writable FD exists and file perms changed. The gofer server should not attempt to re-open the writable FD on server on rename. runsc/fsgofer works as expected. PiperOrigin-RevId: 429197853 --- test/syscalls/linux/BUILD | 1 + test/syscalls/linux/rename.cc | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/test/syscalls/linux/BUILD b/test/syscalls/linux/BUILD index 7f4d64632..88bea0d82 100644 --- a/test/syscalls/linux/BUILD +++ b/test/syscalls/linux/BUILD @@ -2148,6 +2148,7 @@ cc_binary( "//test/util:fs_util", "@com_google_absl//absl/strings", gtest, + "//test/util:save_util", "//test/util:temp_path", "//test/util:test_main", "//test/util:test_util", diff --git a/test/syscalls/linux/rename.cc b/test/syscalls/linux/rename.cc index 561eed99f..dcbc47a88 100644 --- a/test/syscalls/linux/rename.cc +++ b/test/syscalls/linux/rename.cc @@ -23,6 +23,7 @@ #include "test/util/cleanup.h" #include "test/util/file_descriptor.h" #include "test/util/fs_util.h" +#include "test/util/save_util.h" #include "test/util/temp_path.h" #include "test/util/test_util.h" @@ -87,6 +88,19 @@ TEST(RenameTest, FileToSameDirectory) { EXPECT_THAT(Exists(newpath), IsPosixErrorOkAndHolds(true)); } +TEST(RenameTest, RenameAfterWritableFDAndChmod) { + // Restore will require re-opening the writable FD which will fail. + const DisableSave ds; + const std::string data = "hello world\n"; + auto f = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateFile()); + auto wfd = ASSERT_NO_ERRNO_AND_VALUE(Open(f.path(), O_WRONLY)); + ASSERT_THAT(chmod(f.path().c_str(), 0444), SyscallSucceeds()); + std::string const newpath = NewTempAbsPath(); + ASSERT_THAT(rename(f.path().c_str(), newpath.c_str()), SyscallSucceeds()); + EXPECT_THAT(WriteFd(wfd.get(), data.c_str(), data.size()), + SyscallSucceedsWithValue(data.size())); +} + TEST(RenameTest, DirectoryToSameDirectory) { auto dir = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateDir()); std::string const newpath = NewTempAbsPath();