mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
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:
@@ -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",
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user