Allow fsync on a directory.
PiperOrigin-RevId: 229781337 Change-Id: I1f946cff2771714fb1abd83a83ed454e9febda0a
This commit is contained in:
parent
e4d3ca7263
commit
12bc7834dc
|
@ -228,10 +228,10 @@ func (FileNoIoctl) Ioctl(ctx context.Context, io usermem.IO, args arch.SyscallAr
|
||||||
type DirFileOperations struct {
|
type DirFileOperations struct {
|
||||||
waiter.AlwaysReady
|
waiter.AlwaysReady
|
||||||
FileGenericSeek
|
FileGenericSeek
|
||||||
FileNoFsync
|
|
||||||
FileNoIoctl
|
FileNoIoctl
|
||||||
FileNoMMap
|
FileNoMMap
|
||||||
FileNoopFlush
|
FileNoopFlush
|
||||||
|
FileNoopFsync
|
||||||
FileNoopRelease
|
FileNoopRelease
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -783,6 +783,7 @@ cc_binary(
|
||||||
srcs = ["fsync.cc"],
|
srcs = ["fsync.cc"],
|
||||||
linkstatic = 1,
|
linkstatic = 1,
|
||||||
deps = [
|
deps = [
|
||||||
|
"//test/util:file_descriptor",
|
||||||
"//test/util:temp_path",
|
"//test/util:temp_path",
|
||||||
"//test/util:test_main",
|
"//test/util:test_main",
|
||||||
"//test/util:test_util",
|
"//test/util:test_util",
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
#include "test/util/file_descriptor.h"
|
||||||
#include "test/util/temp_path.h"
|
#include "test/util/temp_path.h"
|
||||||
#include "test/util/test_util.h"
|
#include "test/util/test_util.h"
|
||||||
|
|
||||||
|
@ -28,22 +29,24 @@ namespace testing {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
TEST(FsyncTest, TempFileSucceeds) {
|
TEST(FsyncTest, TempFileSucceeds) {
|
||||||
std::string path = NewTempAbsPath();
|
auto file = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateFile());
|
||||||
int fd;
|
auto fd = ASSERT_NO_ERRNO_AND_VALUE(Open(file.path(), O_RDWR, 0666));
|
||||||
EXPECT_THAT(fd = open(path.c_str(), O_RDWR | O_CREAT, 0666),
|
|
||||||
SyscallSucceeds());
|
|
||||||
const std::string data = "some data to sync";
|
const std::string data = "some data to sync";
|
||||||
EXPECT_THAT(write(fd, data.c_str(), data.size()),
|
EXPECT_THAT(write(fd.get(), data.c_str(), data.size()),
|
||||||
SyscallSucceedsWithValue(data.size()));
|
SyscallSucceedsWithValue(data.size()));
|
||||||
EXPECT_THAT(fsync(fd), SyscallSucceeds());
|
EXPECT_THAT(fsync(fd.get()), SyscallSucceeds());
|
||||||
ASSERT_THAT(close(fd), SyscallSucceeds());
|
}
|
||||||
ASSERT_THAT(unlink(path.c_str()), SyscallSucceeds());
|
|
||||||
|
TEST(FsyncTest, TempDirSucceeds) {
|
||||||
|
auto dir = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateDir());
|
||||||
|
auto fd = ASSERT_NO_ERRNO_AND_VALUE(Open(dir.path(), O_RDONLY | O_DIRECTORY));
|
||||||
|
EXPECT_THAT(fsync(fd.get()), SyscallSucceeds());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FsyncTest, CannotFsyncOnUnopenedFd) {
|
TEST(FsyncTest, CannotFsyncOnUnopenedFd) {
|
||||||
|
auto file = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateFile());
|
||||||
int fd;
|
int fd;
|
||||||
auto f = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateFile());
|
ASSERT_THAT(fd = open(file.path().c_str(), O_RDONLY), SyscallSucceeds());
|
||||||
ASSERT_THAT(fd = open(f.path().c_str(), O_RDONLY), SyscallSucceeds());
|
|
||||||
ASSERT_THAT(close(fd), SyscallSucceeds());
|
ASSERT_THAT(close(fd), SyscallSucceeds());
|
||||||
|
|
||||||
// fd is now invalid.
|
// fd is now invalid.
|
||||||
|
|
Loading…
Reference in New Issue