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
This commit is contained in:
Ayush Ranjan
2022-02-16 19:27:56 -08:00
committed by gVisor bot
parent 9b93c12a13
commit ab3728508f
2 changed files with 15 additions and 0 deletions
+1
View File
@@ -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",
+14
View File
@@ -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();