Reland "Remove unsupported perm, symlink calls for Fuchsia."
Reland "Remove unsupported perm, symlink calls for Fuchsia."
The previous CL was landed at the same time as net_unittests,
which depended on calls that were conditionally removed from this CL.
This CL adds !OS_FUCHSIA guards to the relevant ifdef blocks in
url_request_unittest and sql/connection.cc.
Removing these functions from Fuchsia builds will make it easier to
detect and prevent any future regressions, since they'll appear as
build breakages.
R: [email protected]
Bug: 706592
Change-Id: Iad6343a3cb6fcc90b742de04bb8052e77ba498c7
Reviewed-on: https://chromium-review.googlesource.com/569845
Commit-Queue: Kevin Marshall <[email protected]>
Reviewed-by: Victor Costan <[email protected]>
Reviewed-by: David Benjamin <[email protected]>
Reviewed-by: Nico Weber <[email protected]>
Cr-Commit-Position: refs/heads/master@{#486632}
diff --git a/base/files/file_path_watcher_unittest.cc b/base/files/file_path_watcher_unittest.cc
index e280bbc5..9945007 100644
--- a/base/files/file_path_watcher_unittest.cc
+++ b/base/files/file_path_watcher_unittest.cc
@@ -539,15 +539,14 @@
ASSERT_TRUE(WaitForEvents());
}
-#if defined(OS_POSIX)
-#if defined(OS_ANDROID)
+#if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_FUCHSIA)
// Apps cannot create symlinks on Android in /sdcard as /sdcard uses the
// "fuse" file system, while /data uses "ext4". Running these tests in /data
// would be preferable and allow testing file attributes and symlinks.
// TODO(pauljensen): Re-enable when crbug.com/475568 is fixed and SetUp() places
// the |temp_dir_| in /data.
-#define RecursiveWithSymLink DISABLED_RecursiveWithSymLink
-#endif // defined(OS_ANDROID)
+//
+// This test is disabled on Fuchsia since it doesn't support symlinking.
TEST_F(FilePathWatcherTest, RecursiveWithSymLink) {
if (!FilePathWatcher::RecursiveWatchAvailable())
return;
@@ -585,7 +584,7 @@
ASSERT_TRUE(WriteFile(target2_file, "content"));
ASSERT_TRUE(WaitForEvents());
}
-#endif // OS_POSIX
+#endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_FUCHSIA)
TEST_F(FilePathWatcherTest, MoveChild) {
FilePathWatcher file_watcher;
diff --git a/base/files/file_util.h b/base/files/file_util.h
index 27d5ff3..fac14d3 100644
--- a/base/files/file_util.h
+++ b/base/files/file_util.h
@@ -165,6 +165,10 @@
// Returns true iff |bytes| bytes have been successfully read from |fd|.
BASE_EXPORT bool ReadFromFD(int fd, char* buffer, size_t bytes);
+// The following functions use POSIX functionality that isn't supported by
+// Fuchsia.
+#if !defined(OS_FUCHSIA)
+
// Creates a symbolic link at |symlink| pointing to |target|. Returns
// false on failure.
BASE_EXPORT bool CreateSymbolicLink(const FilePath& target,
@@ -205,6 +209,7 @@
BASE_EXPORT bool ExecutableExistsInPath(Environment* env,
const FilePath::StringType& executable);
+#endif // !OS_FUCHSIA
#endif // OS_POSIX
// Returns true if the given directory is empty
diff --git a/base/files/file_util_posix.cc b/base/files/file_util_posix.cc
index 018592a..de9da50 100644
--- a/base/files/file_util_posix.cc
+++ b/base/files/file_util_posix.cc
@@ -438,6 +438,8 @@
}
#if !defined(OS_NACL_NONSFI)
+
+#if !defined(OS_FUCHSIA)
bool CreateSymbolicLink(const FilePath& target_path,
const FilePath& symlink_path) {
DCHECK(!symlink_path.empty());
@@ -514,6 +516,8 @@
return false;
}
+#endif // !OS_FUCHSIA
+
#if !defined(OS_MACOSX)
// This is implemented in file_util_mac.mm for Mac.
bool GetTempDir(FilePath* path) {
diff --git a/base/files/file_util_unittest.cc b/base/files/file_util_unittest.cc
index ed7adf91..8f3ffbf2 100644
--- a/base/files/file_util_unittest.cc
+++ b/base/files/file_util_unittest.cc
@@ -163,6 +163,8 @@
#endif
+// Fuchsia doesn't support file permissions.
+#if !defined(OS_FUCHSIA)
#if defined(OS_POSIX)
// Provide a simple way to change the permissions bits on |path| in tests.
// ASSERT failures will return, but not stop the test. Caller should wrap
@@ -181,6 +183,48 @@
}
#endif // defined(OS_POSIX)
+// Sets the source file to read-only.
+void SetReadOnly(const FilePath& path, bool read_only) {
+#if defined(OS_WIN)
+ // On Windows, it involves setting/removing the 'readonly' bit.
+ DWORD attrs = GetFileAttributes(path.value().c_str());
+ ASSERT_NE(INVALID_FILE_ATTRIBUTES, attrs);
+ ASSERT_TRUE(SetFileAttributes(
+ path.value().c_str(), read_only ? (attrs | FILE_ATTRIBUTE_READONLY)
+ : (attrs & ~FILE_ATTRIBUTE_READONLY)));
+
+ DWORD expected =
+ read_only
+ ? ((attrs & (FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_DIRECTORY)) |
+ FILE_ATTRIBUTE_READONLY)
+ : (attrs & (FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_DIRECTORY));
+
+ // Ignore FILE_ATTRIBUTE_NOT_CONTENT_INDEXED if present.
+ attrs = GetFileAttributes(path.value().c_str()) &
+ ~FILE_ATTRIBUTE_NOT_CONTENT_INDEXED;
+ ASSERT_EQ(expected, attrs);
+#else
+ // On all other platforms, it involves removing/setting the write bit.
+ mode_t mode = read_only ? S_IRUSR : (S_IRUSR | S_IWUSR);
+ EXPECT_TRUE(SetPosixFilePermissions(
+ path, DirectoryExists(path) ? (mode | S_IXUSR) : mode));
+#endif // defined(OS_WIN)
+}
+
+bool IsReadOnly(const FilePath& path) {
+#if defined(OS_WIN)
+ DWORD attrs = GetFileAttributes(path.value().c_str());
+ EXPECT_NE(INVALID_FILE_ATTRIBUTES, attrs);
+ return attrs & FILE_ATTRIBUTE_READONLY;
+#else
+ int mode = 0;
+ EXPECT_TRUE(GetPosixFilePermissions(path, &mode));
+ return !(mode & S_IWUSR);
+#endif // defined(OS_WIN)
+}
+
+#endif // defined(OS_FUCHSIA)
+
const wchar_t bogus_content[] = L"I'm cannon fodder.";
const int FILES_AND_DIRECTORIES =
@@ -575,7 +619,7 @@
#endif // defined(OS_WIN)
-#if defined(OS_POSIX)
+#if !defined(OS_FUCHSIA) && defined(OS_POSIX)
TEST_F(FileUtilTest, CreateAndReadSymlinks) {
FilePath link_from = temp_dir_.GetPath().Append(FPL("from_file"));
@@ -650,51 +694,7 @@
// Infinite loop!
EXPECT_FALSE(NormalizeFilePath(link_from, &normalized_path));
}
-#endif // defined(OS_POSIX)
-TEST_F(FileUtilTest, DeleteNonExistent) {
- FilePath non_existent =
- temp_dir_.GetPath().AppendASCII("bogus_file_dne.foobar");
- ASSERT_FALSE(PathExists(non_existent));
-
- EXPECT_TRUE(DeleteFile(non_existent, false));
- ASSERT_FALSE(PathExists(non_existent));
- EXPECT_TRUE(DeleteFile(non_existent, true));
- ASSERT_FALSE(PathExists(non_existent));
-}
-
-TEST_F(FileUtilTest, DeleteNonExistentWithNonExistentParent) {
- FilePath non_existent = temp_dir_.GetPath().AppendASCII("bogus_topdir");
- non_existent = non_existent.AppendASCII("bogus_subdir");
- ASSERT_FALSE(PathExists(non_existent));
-
- EXPECT_TRUE(DeleteFile(non_existent, false));
- ASSERT_FALSE(PathExists(non_existent));
- EXPECT_TRUE(DeleteFile(non_existent, true));
- ASSERT_FALSE(PathExists(non_existent));
-}
-
-TEST_F(FileUtilTest, DeleteFile) {
- // Create a file
- FilePath file_name = temp_dir_.GetPath().Append(FPL("Test DeleteFile 1.txt"));
- CreateTextFile(file_name, bogus_content);
- ASSERT_TRUE(PathExists(file_name));
-
- // Make sure it's deleted
- EXPECT_TRUE(DeleteFile(file_name, false));
- EXPECT_FALSE(PathExists(file_name));
-
- // Test recursive case, create a new file
- file_name = temp_dir_.GetPath().Append(FPL("Test DeleteFile 2.txt"));
- CreateTextFile(file_name, bogus_content);
- ASSERT_TRUE(PathExists(file_name));
-
- // Make sure it's deleted
- EXPECT_TRUE(DeleteFile(file_name, true));
- EXPECT_FALSE(PathExists(file_name));
-}
-
-#if defined(OS_POSIX)
TEST_F(FileUtilTest, DeleteSymlinkToExistentFile) {
// Create a file.
FilePath file_name = temp_dir_.GetPath().Append(FPL("Test DeleteFile 2.txt"));
@@ -907,7 +907,105 @@
EXPECT_FALSE(ExecutableExistsInPath(env.get(), kDneFileName));
}
-#endif // defined(OS_POSIX)
+#endif // !defined(OS_FUCHSIA) && defined(OS_POSIX)
+
+#if !defined(OS_FUCHSIA)
+
+TEST_F(FileUtilTest, CopyFileACL) {
+ // While FileUtilTest.CopyFile asserts the content is correctly copied over,
+ // this test case asserts the access control bits are meeting expectations in
+ // CopyFile().
+ FilePath src = temp_dir_.GetPath().Append(FILE_PATH_LITERAL("src.txt"));
+ const std::wstring file_contents(L"Gooooooooooooooooooooogle");
+ CreateTextFile(src, file_contents);
+
+ // Set the source file to read-only.
+ ASSERT_FALSE(IsReadOnly(src));
+ SetReadOnly(src, true);
+ ASSERT_TRUE(IsReadOnly(src));
+
+ // Copy the file.
+ FilePath dst = temp_dir_.GetPath().Append(FILE_PATH_LITERAL("dst.txt"));
+ ASSERT_TRUE(CopyFile(src, dst));
+ EXPECT_EQ(file_contents, ReadTextFile(dst));
+
+ ASSERT_FALSE(IsReadOnly(dst));
+}
+
+TEST_F(FileUtilTest, CopyDirectoryACL) {
+ // Create source directories.
+ FilePath src = temp_dir_.GetPath().Append(FILE_PATH_LITERAL("src"));
+ FilePath src_subdir = src.Append(FILE_PATH_LITERAL("subdir"));
+ CreateDirectory(src_subdir);
+ ASSERT_TRUE(PathExists(src_subdir));
+
+ // Create a file under the directory.
+ FilePath src_file = src.Append(FILE_PATH_LITERAL("src.txt"));
+ CreateTextFile(src_file, L"Gooooooooooooooooooooogle");
+ SetReadOnly(src_file, true);
+ ASSERT_TRUE(IsReadOnly(src_file));
+
+ // Make directory read-only.
+ SetReadOnly(src_subdir, true);
+ ASSERT_TRUE(IsReadOnly(src_subdir));
+
+ // Copy the directory recursively.
+ FilePath dst = temp_dir_.GetPath().Append(FILE_PATH_LITERAL("dst"));
+ FilePath dst_file = dst.Append(FILE_PATH_LITERAL("src.txt"));
+ EXPECT_TRUE(CopyDirectory(src, dst, true));
+
+ FilePath dst_subdir = dst.Append(FILE_PATH_LITERAL("subdir"));
+ ASSERT_FALSE(IsReadOnly(dst_subdir));
+ ASSERT_FALSE(IsReadOnly(dst_file));
+
+ // Give write permissions to allow deletion.
+ SetReadOnly(src_subdir, false);
+ ASSERT_FALSE(IsReadOnly(src_subdir));
+}
+
+#endif // !defined(OS_FUCHSIA)
+
+TEST_F(FileUtilTest, DeleteNonExistent) {
+ FilePath non_existent =
+ temp_dir_.GetPath().AppendASCII("bogus_file_dne.foobar");
+ ASSERT_FALSE(PathExists(non_existent));
+
+ EXPECT_TRUE(DeleteFile(non_existent, false));
+ ASSERT_FALSE(PathExists(non_existent));
+ EXPECT_TRUE(DeleteFile(non_existent, true));
+ ASSERT_FALSE(PathExists(non_existent));
+}
+
+TEST_F(FileUtilTest, DeleteNonExistentWithNonExistentParent) {
+ FilePath non_existent = temp_dir_.GetPath().AppendASCII("bogus_topdir");
+ non_existent = non_existent.AppendASCII("bogus_subdir");
+ ASSERT_FALSE(PathExists(non_existent));
+
+ EXPECT_TRUE(DeleteFile(non_existent, false));
+ ASSERT_FALSE(PathExists(non_existent));
+ EXPECT_TRUE(DeleteFile(non_existent, true));
+ ASSERT_FALSE(PathExists(non_existent));
+}
+
+TEST_F(FileUtilTest, DeleteFile) {
+ // Create a file
+ FilePath file_name = temp_dir_.GetPath().Append(FPL("Test DeleteFile 1.txt"));
+ CreateTextFile(file_name, bogus_content);
+ ASSERT_TRUE(PathExists(file_name));
+
+ // Make sure it's deleted
+ EXPECT_TRUE(DeleteFile(file_name, false));
+ EXPECT_FALSE(PathExists(file_name));
+
+ // Test recursive case, create a new file
+ file_name = temp_dir_.GetPath().Append(FPL("Test DeleteFile 2.txt"));
+ CreateTextFile(file_name, bogus_content);
+ ASSERT_TRUE(PathExists(file_name));
+
+ // Make sure it's deleted
+ EXPECT_TRUE(DeleteFile(file_name, true));
+ EXPECT_FALSE(PathExists(file_name));
+}
#if defined(OS_WIN)
// Tests that the Delete function works for wild cards, especially
@@ -1452,77 +1550,6 @@
EXPECT_TRUE(PathExists(file_name_to));
}
-// Sets the source file to read-only.
-void SetReadOnly(const FilePath& path, bool read_only) {
-#if defined(OS_WIN)
- // On Windows, it involves setting/removing the 'readonly' bit.
- DWORD attrs = GetFileAttributes(path.value().c_str());
- ASSERT_NE(INVALID_FILE_ATTRIBUTES, attrs);
- ASSERT_TRUE(SetFileAttributes(
- path.value().c_str(),
- read_only ? (attrs | FILE_ATTRIBUTE_READONLY) :
- (attrs & ~FILE_ATTRIBUTE_READONLY)));
-
- DWORD expected = read_only ?
- ((attrs & (FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_DIRECTORY)) |
- FILE_ATTRIBUTE_READONLY) :
- (attrs & (FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_DIRECTORY));
-
- // Ignore FILE_ATTRIBUTE_NOT_CONTENT_INDEXED if present.
- attrs = GetFileAttributes(path.value().c_str()) &
- ~FILE_ATTRIBUTE_NOT_CONTENT_INDEXED;
- ASSERT_EQ(expected, attrs);
-#else
- // On all other platforms, it involves removing/setting the write bit.
- mode_t mode = read_only ? S_IRUSR : (S_IRUSR | S_IWUSR);
- EXPECT_TRUE(SetPosixFilePermissions(
- path, DirectoryExists(path) ? (mode | S_IXUSR) : mode));
-#endif
-}
-
-bool IsReadOnly(const FilePath& path) {
-#if defined(OS_WIN)
- DWORD attrs = GetFileAttributes(path.value().c_str());
- EXPECT_NE(INVALID_FILE_ATTRIBUTES, attrs);
- return attrs & FILE_ATTRIBUTE_READONLY;
-#else
- int mode = 0;
- EXPECT_TRUE(GetPosixFilePermissions(path, &mode));
- return !(mode & S_IWUSR);
-#endif
-}
-
-TEST_F(FileUtilTest, CopyDirectoryACL) {
- // Create source directories.
- FilePath src = temp_dir_.GetPath().Append(FILE_PATH_LITERAL("src"));
- FilePath src_subdir = src.Append(FILE_PATH_LITERAL("subdir"));
- CreateDirectory(src_subdir);
- ASSERT_TRUE(PathExists(src_subdir));
-
- // Create a file under the directory.
- FilePath src_file = src.Append(FILE_PATH_LITERAL("src.txt"));
- CreateTextFile(src_file, L"Gooooooooooooooooooooogle");
- SetReadOnly(src_file, true);
- ASSERT_TRUE(IsReadOnly(src_file));
-
- // Make directory read-only.
- SetReadOnly(src_subdir, true);
- ASSERT_TRUE(IsReadOnly(src_subdir));
-
- // Copy the directory recursively.
- FilePath dst = temp_dir_.GetPath().Append(FILE_PATH_LITERAL("dst"));
- FilePath dst_file = dst.Append(FILE_PATH_LITERAL("src.txt"));
- EXPECT_TRUE(CopyDirectory(src, dst, true));
-
- FilePath dst_subdir = dst.Append(FILE_PATH_LITERAL("subdir"));
- ASSERT_FALSE(IsReadOnly(dst_subdir));
- ASSERT_FALSE(IsReadOnly(dst_file));
-
- // Give write permissions to allow deletion.
- SetReadOnly(src_subdir, false);
- ASSERT_FALSE(IsReadOnly(src_subdir));
-}
-
TEST_F(FileUtilTest, CopyFile) {
// Create a directory
FilePath dir_name_from =
@@ -1560,27 +1587,6 @@
EXPECT_FALSE(PathExists(dest_file2));
}
-TEST_F(FileUtilTest, CopyFileACL) {
- // While FileUtilTest.CopyFile asserts the content is correctly copied over,
- // this test case asserts the access control bits are meeting expectations in
- // CopyFile().
- FilePath src = temp_dir_.GetPath().Append(FILE_PATH_LITERAL("src.txt"));
- const std::wstring file_contents(L"Gooooooooooooooooooooogle");
- CreateTextFile(src, file_contents);
-
- // Set the source file to read-only.
- ASSERT_FALSE(IsReadOnly(src));
- SetReadOnly(src, true);
- ASSERT_TRUE(IsReadOnly(src));
-
- // Copy the file.
- FilePath dst = temp_dir_.GetPath().Append(FILE_PATH_LITERAL("dst.txt"));
- ASSERT_TRUE(CopyFile(src, dst));
- EXPECT_EQ(file_contents, ReadTextFile(dst));
-
- ASSERT_FALSE(IsReadOnly(dst));
-}
-
// file_util winds up using autoreleased objects on the Mac, so this needs
// to be a PlatformTest.
typedef PlatformTest ReadOnlyFileUtilTest;
@@ -2255,6 +2261,7 @@
}
#if defined(OS_POSIX)
+
TEST_F(FileUtilTest, SetNonBlocking) {
const int kInvalidFd = 99999;
EXPECT_FALSE(SetNonBlocking(kInvalidFd));
@@ -2279,6 +2286,10 @@
EXPECT_TRUE(SetCloseOnExec(fd.get()));
}
+#endif
+
+#if defined(OS_POSIX) && !defined(OS_FUCHSIA)
+
// Testing VerifyPathControlledByAdmin() is hard, because there is no
// way a test can make a file owned by root, or change file paths
// at the root of the file system. VerifyPathControlledByAdmin()
@@ -2561,6 +2572,8 @@
EXPECT_TRUE(VerifyPathControlledByUser(sub_dir_, text_file_, uid_, ok_gids_));
}
+#endif // defined(OS_POSIX) && !defined(OS_FUCHSIA)
+
#if defined(OS_ANDROID)
TEST_F(FileUtilTest, ValidContentUriTest) {
// Get the test image path.
@@ -2606,6 +2619,8 @@
}
#endif
+#if defined(OS_POSIX)
+
TEST(ScopedFD, ScopedFDDoesClose) {
int fds[2];
char c = 0;
diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc
index 09b9c28..083cd24 100644
--- a/net/url_request/url_request_unittest.cc
+++ b/net/url_request/url_request_unittest.cc
@@ -1166,7 +1166,7 @@
}
}
-#if defined(OS_POSIX) // Bacause of symbolic links.
+#if defined(OS_POSIX) && !defined(OS_FUCHSIA) // Because of symbolic links.
TEST_F(URLRequestTest, SymlinksToFiles) {
base::ScopedTempDir temp_dir;
@@ -1290,7 +1290,7 @@
}
}
-#endif // defined(OS_POSIX)
+#endif // defined(OS_POSIX) && !defined(OS_FUCHSIA)
TEST_F(URLRequestTest, FileDirCancelTest) {
// Put in mock resource provider.
diff --git a/sql/connection.cc b/sql/connection.cc
index c80758f..d7477f57 100644
--- a/sql/connection.cc
+++ b/sql/connection.cc
@@ -31,6 +31,7 @@
#include "base/synchronization/lock.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/trace_event/memory_dump_manager.h"
+#include "build/build_config.h"
#include "sql/connection_memory_dump_provider.h"
#include "sql/meta_table.h"
#include "sql/statement.h"
@@ -1726,7 +1727,7 @@
}
// TODO(shess): OS_WIN support?
-#if defined(OS_POSIX)
+#if defined(OS_POSIX) && !defined(OS_FUCHSIA)
if (restrict_to_user_) {
DCHECK_NE(file_name, std::string(":memory"));
base::FilePath file_path(file_name);
@@ -1747,7 +1748,7 @@
base::SetPosixFilePermissions(wal_path, mode);
}
}
-#endif // defined(OS_POSIX)
+#endif // defined(OS_POSIX) && !defined(OS_FUCHSIA)
// SQLite uses a lookaside buffer to improve performance of small mallocs.
// Chromium already depends on small mallocs being efficient, so we disable
diff --git a/testing/buildbot/filters/fuchsia.base_unittests.filter b/testing/buildbot/filters/fuchsia.base_unittests.filter
index f97655e..0bb4af8 100644
--- a/testing/buildbot/filters/fuchsia.base_unittests.filter
+++ b/testing/buildbot/filters/fuchsia.base_unittests.filter
@@ -27,17 +27,7 @@
-FilePersistentMemoryAllocatorTest.ExtendTest
-FileProxyTest.SetTimes
-FileUtilProxyTest.Touch
--FileUtilTest.ChangeDirectoryPermissionsAndEnumerate
--FileUtilTest.ChangeFilePermissionsAndRead
--FileUtilTest.ChangeFilePermissionsAndWrite
--FileUtilTest.CopyDirectoryACL
--FileUtilTest.CopyFileACL
--FileUtilTest.CreateAndReadSymlinks
--FileUtilTest.DeleteSymlinkToExistentFile
--FileUtilTest.DeleteSymlinkToNonExistentFile
--FileUtilTest.ExecutableExistsInPath
-FileUtilTest.FileToFILE
--FileUtilTest.NormalizeFilePathSymlinks
-LoggingTest.CheckCausesDistinctBreakpoints
-MemoryMappedFileTest.ExtendableFile
-MemoryMappedFileTest.MapLargePartialRegionInTheMiddle