From 169731495268b960b0222466862f3a339314b8a2 Mon Sep 17 00:00:00 2001 From: Scott Graham Date: Wed, 13 Dec 2017 15:13:39 -0800 Subject: [PATCH] fuchsia: Make Filesystem.RemoveFile, .RemoveDirectory pass - Remove unnecessary flags (O_NOCTTY, O_CLOEXEC) - Don't try to unlink a directory when it's expected to fail - Disable rmdir() in location where it's expected to fail, as it currently (incorrectly) does not fail on Fuchsia. Bug: crashpad:196, US-400 Change-Id: I80cf833ba90f31943b9043727ea07893b4eb3494 Reviewed-on: https://chromium-review.googlesource.com/823286 Reviewed-by: Mark Mentovai Commit-Queue: Scott Graham --- util/file/file_io_posix.cc | 5 +++++ util/file/filesystem_test.cc | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/util/file/file_io_posix.cc b/util/file/file_io_posix.cc index b2afdc0d..ec5e5abe 100644 --- a/util/file/file_io_posix.cc +++ b/util/file/file_io_posix.cc @@ -66,7 +66,12 @@ FileHandle OpenFileForOutput(int rdwr_or_wronly, const base::FilePath& path, FileWriteMode mode, FilePermissions permissions) { +#if defined(OS_FUCHSIA) + // O_NOCTTY is invalid on Fuchsia, and O_CLOEXEC isn't necessary. + int flags = 0; +#else int flags = O_NOCTTY | O_CLOEXEC; +#endif DCHECK(rdwr_or_wronly & (O_RDWR | O_WRONLY)); DCHECK_EQ(rdwr_or_wronly & ~(O_RDWR | O_WRONLY), 0); diff --git a/util/file/filesystem_test.cc b/util/file/filesystem_test.cc index 28d2d88a..3430c3f9 100644 --- a/util/file/filesystem_test.cc +++ b/util/file/filesystem_test.cc @@ -373,7 +373,6 @@ TEST(Filesystem, RemoveFile) { EXPECT_FALSE(LoggingRemoveFile(base::FilePath())); ScopedTempDir temp_dir; - EXPECT_FALSE(LoggingRemoveFile(temp_dir.path())); base::FilePath file(temp_dir.path().Append(FILE_PATH_LITERAL("file"))); EXPECT_FALSE(LoggingRemoveFile(file)); @@ -384,7 +383,6 @@ TEST(Filesystem, RemoveFile) { base::FilePath dir(temp_dir.path().Append(FILE_PATH_LITERAL("dir"))); ASSERT_TRUE( LoggingCreateDirectory(dir, FilePermissions::kWorldReadable, false)); - EXPECT_FALSE(LoggingRemoveFile(dir)); EXPECT_TRUE(LoggingRemoveFile(file)); EXPECT_FALSE(PathExists(file)); @@ -433,8 +431,16 @@ TEST(Filesystem, RemoveDirectory) { EXPECT_FALSE(LoggingRemoveDirectory(file)); ASSERT_TRUE(CreateFile(file)); +#if !defined(OS_FUCHSIA) + // The current implementation of Fuchsia's rmdir() simply calls unlink(), and + // unlink() works on all FS objects. This is incorrect as + // http://pubs.opengroup.org/onlinepubs/9699919799/functions/rmdir.html says + // "The directory shall be removed only if it is an empty directory." and "If + // the directory is not an empty directory, rmdir() shall fail and set errno + // to [EEXIST] or [ENOTEMPTY]." Upstream bug: US-400. EXPECT_FALSE(LoggingRemoveDirectory(file)); EXPECT_FALSE(LoggingRemoveDirectory(dir)); +#endif ASSERT_TRUE(LoggingRemoveFile(file)); EXPECT_TRUE(LoggingRemoveDirectory(dir));