| Index: base/files/file_util_unittest.cc
|
| diff --git a/base/files/file_util_unittest.cc b/base/files/file_util_unittest.cc
|
| index 52581f8ce4310a9af5c887831d134ae11c93b795..933993347168fabdf9ce270d44a88258999ce6c1 100644
|
| --- a/base/files/file_util_unittest.cc
|
| +++ b/base/files/file_util_unittest.cc
|
| @@ -4,14 +4,6 @@
|
|
|
| #include "build/build_config.h"
|
|
|
| -#if defined(OS_WIN)
|
| -#include <windows.h>
|
| -#include <shellapi.h>
|
| -#include <shlobj.h>
|
| -#include <tchar.h>
|
| -#include <winioctl.h>
|
| -#endif
|
| -
|
| #if defined(OS_POSIX)
|
| #include <errno.h>
|
| #include <fcntl.h>
|
| @@ -37,11 +29,6 @@
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "testing/platform_test.h"
|
|
|
| -#if defined(OS_WIN)
|
| -#include "base/win/scoped_handle.h"
|
| -#include "base/win/windows_version.h"
|
| -#endif
|
| -
|
| #if defined(OS_ANDROID)
|
| #include "base/android/content_uri_utils.h"
|
| #endif
|
| @@ -55,109 +42,6 @@ namespace {
|
|
|
| // To test that NormalizeFilePath() deals with NTFS reparse points correctly,
|
| // we need functions to create and delete reparse points.
|
| -#if defined(OS_WIN)
|
| -typedef struct _REPARSE_DATA_BUFFER {
|
| - ULONG ReparseTag;
|
| - USHORT ReparseDataLength;
|
| - USHORT Reserved;
|
| - union {
|
| - struct {
|
| - USHORT SubstituteNameOffset;
|
| - USHORT SubstituteNameLength;
|
| - USHORT PrintNameOffset;
|
| - USHORT PrintNameLength;
|
| - ULONG Flags;
|
| - WCHAR PathBuffer[1];
|
| - } SymbolicLinkReparseBuffer;
|
| - struct {
|
| - USHORT SubstituteNameOffset;
|
| - USHORT SubstituteNameLength;
|
| - USHORT PrintNameOffset;
|
| - USHORT PrintNameLength;
|
| - WCHAR PathBuffer[1];
|
| - } MountPointReparseBuffer;
|
| - struct {
|
| - UCHAR DataBuffer[1];
|
| - } GenericReparseBuffer;
|
| - };
|
| -} REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER;
|
| -
|
| -// Sets a reparse point. |source| will now point to |target|. Returns true if
|
| -// the call succeeds, false otherwise.
|
| -bool SetReparsePoint(HANDLE source, const FilePath& target_path) {
|
| - std::wstring kPathPrefix = L"\\??\\";
|
| - std::wstring target_str;
|
| - // The juction will not work if the target path does not start with \??\ .
|
| - if (kPathPrefix != target_path.value().substr(0, kPathPrefix.size()))
|
| - target_str += kPathPrefix;
|
| - target_str += target_path.value();
|
| - const wchar_t* target = target_str.c_str();
|
| - USHORT size_target = static_cast<USHORT>(wcslen(target)) * sizeof(target[0]);
|
| - char buffer[2000] = {0};
|
| - DWORD returned;
|
| -
|
| - REPARSE_DATA_BUFFER* data = reinterpret_cast<REPARSE_DATA_BUFFER*>(buffer);
|
| -
|
| - data->ReparseTag = 0xa0000003;
|
| - memcpy(data->MountPointReparseBuffer.PathBuffer, target, size_target + 2);
|
| -
|
| - data->MountPointReparseBuffer.SubstituteNameLength = size_target;
|
| - data->MountPointReparseBuffer.PrintNameOffset = size_target + 2;
|
| - data->ReparseDataLength = size_target + 4 + 8;
|
| -
|
| - int data_size = data->ReparseDataLength + 8;
|
| -
|
| - if (!DeviceIoControl(source, FSCTL_SET_REPARSE_POINT, &buffer, data_size,
|
| - NULL, 0, &returned, NULL)) {
|
| - return false;
|
| - }
|
| - return true;
|
| -}
|
| -
|
| -// Delete the reparse point referenced by |source|. Returns true if the call
|
| -// succeeds, false otherwise.
|
| -bool DeleteReparsePoint(HANDLE source) {
|
| - DWORD returned;
|
| - REPARSE_DATA_BUFFER data = {0};
|
| - data.ReparseTag = 0xa0000003;
|
| - if (!DeviceIoControl(source, FSCTL_DELETE_REPARSE_POINT, &data, 8, NULL, 0,
|
| - &returned, NULL)) {
|
| - return false;
|
| - }
|
| - return true;
|
| -}
|
| -
|
| -// Manages a reparse point for a test.
|
| -class ReparsePoint {
|
| - public:
|
| - // Creates a reparse point from |source| (an empty directory) to |target|.
|
| - ReparsePoint(const FilePath& source, const FilePath& target) {
|
| - dir_.Set(
|
| - ::CreateFile(source.value().c_str(),
|
| - FILE_ALL_ACCESS,
|
| - FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
|
| - NULL,
|
| - OPEN_EXISTING,
|
| - FILE_FLAG_BACKUP_SEMANTICS, // Needed to open a directory.
|
| - NULL));
|
| - created_ = dir_.IsValid() && SetReparsePoint(dir_.Get(), target);
|
| - }
|
| -
|
| - ~ReparsePoint() {
|
| - if (created_)
|
| - DeleteReparsePoint(dir_.Get());
|
| - }
|
| -
|
| - bool IsValid() { return created_; }
|
| -
|
| - private:
|
| - win::ScopedHandle dir_;
|
| - bool created_;
|
| - DISALLOW_COPY_AND_ASSIGN(ReparsePoint);
|
| -};
|
| -
|
| -#endif
|
| -
|
| #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
|
| @@ -244,15 +128,6 @@ std::wstring ReadTextFile(const FilePath& filename) {
|
| return std::wstring(contents);
|
| }
|
|
|
| -#if defined(OS_WIN)
|
| -uint64 FileTimeAsUint64(const FILETIME& ft) {
|
| - ULARGE_INTEGER u;
|
| - u.LowPart = ft.dwLowDateTime;
|
| - u.HighPart = ft.dwHighDateTime;
|
| - return u.QuadPart;
|
| -}
|
| -#endif
|
| -
|
| TEST_F(FileUtilTest, FileAndDirectorySize) {
|
| // Create three files of 20, 30 and 3 chars (utf8). ComputeDirectorySize
|
| // should return 53 bytes.
|
| @@ -309,251 +184,6 @@ TEST_F(FileUtilTest, NormalizeFilePathBasic) {
|
| .IsParent(normalized_file_b_path.DirName()));
|
| }
|
|
|
| -#if defined(OS_WIN)
|
| -
|
| -TEST_F(FileUtilTest, NormalizeFilePathReparsePoints) {
|
| - // Build the following directory structure:
|
| - //
|
| - // temp_dir
|
| - // |-> base_a
|
| - // | |-> sub_a
|
| - // | |-> file.txt
|
| - // | |-> long_name___... (Very long name.)
|
| - // | |-> sub_long
|
| - // | |-> deep.txt
|
| - // |-> base_b
|
| - // |-> to_sub_a (reparse point to temp_dir\base_a\sub_a)
|
| - // |-> to_base_b (reparse point to temp_dir\base_b)
|
| - // |-> to_sub_long (reparse point to temp_dir\sub_a\long_name_\sub_long)
|
| -
|
| - FilePath base_a = temp_dir_.path().Append(FPL("base_a"));
|
| -#if defined(OS_WIN)
|
| - // TEMP can have a lower case drive letter.
|
| - string16 temp_base_a = base_a.value();
|
| - ASSERT_FALSE(temp_base_a.empty());
|
| - *temp_base_a.begin() = ToUpperASCII(*temp_base_a.begin());
|
| - base_a = FilePath(temp_base_a);
|
| -#endif
|
| - ASSERT_TRUE(CreateDirectory(base_a));
|
| -
|
| - FilePath sub_a = base_a.Append(FPL("sub_a"));
|
| - ASSERT_TRUE(CreateDirectory(sub_a));
|
| -
|
| - FilePath file_txt = sub_a.Append(FPL("file.txt"));
|
| - CreateTextFile(file_txt, bogus_content);
|
| -
|
| - // Want a directory whose name is long enough to make the path to the file
|
| - // inside just under MAX_PATH chars. This will be used to test that when
|
| - // a junction expands to a path over MAX_PATH chars in length,
|
| - // NormalizeFilePath() fails without crashing.
|
| - FilePath sub_long_rel(FPL("sub_long"));
|
| - FilePath deep_txt(FPL("deep.txt"));
|
| -
|
| - int target_length = MAX_PATH;
|
| - target_length -= (sub_a.value().length() + 1); // +1 for the sepperator '\'.
|
| - target_length -= (sub_long_rel.Append(deep_txt).value().length() + 1);
|
| - // Without making the path a bit shorter, CreateDirectory() fails.
|
| - // the resulting path is still long enough to hit the failing case in
|
| - // NormalizePath().
|
| - const int kCreateDirLimit = 4;
|
| - target_length -= kCreateDirLimit;
|
| - FilePath::StringType long_name_str = FPL("long_name_");
|
| - long_name_str.resize(target_length, '_');
|
| -
|
| - FilePath long_name = sub_a.Append(FilePath(long_name_str));
|
| - FilePath deep_file = long_name.Append(sub_long_rel).Append(deep_txt);
|
| - ASSERT_EQ(MAX_PATH - kCreateDirLimit, deep_file.value().length());
|
| -
|
| - FilePath sub_long = deep_file.DirName();
|
| - ASSERT_TRUE(CreateDirectory(sub_long));
|
| - CreateTextFile(deep_file, bogus_content);
|
| -
|
| - FilePath base_b = temp_dir_.path().Append(FPL("base_b"));
|
| - ASSERT_TRUE(CreateDirectory(base_b));
|
| -
|
| - FilePath to_sub_a = base_b.Append(FPL("to_sub_a"));
|
| - ASSERT_TRUE(CreateDirectory(to_sub_a));
|
| - FilePath normalized_path;
|
| - {
|
| - ReparsePoint reparse_to_sub_a(to_sub_a, sub_a);
|
| - ASSERT_TRUE(reparse_to_sub_a.IsValid());
|
| -
|
| - FilePath to_base_b = base_b.Append(FPL("to_base_b"));
|
| - ASSERT_TRUE(CreateDirectory(to_base_b));
|
| - ReparsePoint reparse_to_base_b(to_base_b, base_b);
|
| - ASSERT_TRUE(reparse_to_base_b.IsValid());
|
| -
|
| - FilePath to_sub_long = base_b.Append(FPL("to_sub_long"));
|
| - ASSERT_TRUE(CreateDirectory(to_sub_long));
|
| - ReparsePoint reparse_to_sub_long(to_sub_long, sub_long);
|
| - ASSERT_TRUE(reparse_to_sub_long.IsValid());
|
| -
|
| - // Normalize a junction free path: base_a\sub_a\file.txt .
|
| - ASSERT_TRUE(NormalizeFilePath(file_txt, &normalized_path));
|
| - ASSERT_STREQ(file_txt.value().c_str(), normalized_path.value().c_str());
|
| -
|
| - // Check that the path base_b\to_sub_a\file.txt can be normalized to exclude
|
| - // the junction to_sub_a.
|
| - ASSERT_TRUE(NormalizeFilePath(to_sub_a.Append(FPL("file.txt")),
|
| - &normalized_path));
|
| - ASSERT_STREQ(file_txt.value().c_str(), normalized_path.value().c_str());
|
| -
|
| - // Check that the path base_b\to_base_b\to_base_b\to_sub_a\file.txt can be
|
| - // normalized to exclude junctions to_base_b and to_sub_a .
|
| - ASSERT_TRUE(NormalizeFilePath(base_b.Append(FPL("to_base_b"))
|
| - .Append(FPL("to_base_b"))
|
| - .Append(FPL("to_sub_a"))
|
| - .Append(FPL("file.txt")),
|
| - &normalized_path));
|
| - ASSERT_STREQ(file_txt.value().c_str(), normalized_path.value().c_str());
|
| -
|
| - // A long enough path will cause NormalizeFilePath() to fail. Make a long
|
| - // path using to_base_b many times, and check that paths long enough to fail
|
| - // do not cause a crash.
|
| - FilePath long_path = base_b;
|
| - const int kLengthLimit = MAX_PATH + 200;
|
| - while (long_path.value().length() <= kLengthLimit) {
|
| - long_path = long_path.Append(FPL("to_base_b"));
|
| - }
|
| - long_path = long_path.Append(FPL("to_sub_a"))
|
| - .Append(FPL("file.txt"));
|
| -
|
| - ASSERT_FALSE(NormalizeFilePath(long_path, &normalized_path));
|
| -
|
| - // Normalizing the junction to deep.txt should fail, because the expanded
|
| - // path to deep.txt is longer than MAX_PATH.
|
| - ASSERT_FALSE(NormalizeFilePath(to_sub_long.Append(deep_txt),
|
| - &normalized_path));
|
| -
|
| - // Delete the reparse points, and see that NormalizeFilePath() fails
|
| - // to traverse them.
|
| - }
|
| -
|
| - ASSERT_FALSE(NormalizeFilePath(to_sub_a.Append(FPL("file.txt")),
|
| - &normalized_path));
|
| -}
|
| -
|
| -TEST_F(FileUtilTest, DevicePathToDriveLetter) {
|
| - // Get a drive letter.
|
| - std::wstring real_drive_letter = temp_dir_.path().value().substr(0, 2);
|
| - StringToUpperASCII(&real_drive_letter);
|
| - if (!isalpha(real_drive_letter[0]) || ':' != real_drive_letter[1]) {
|
| - LOG(ERROR) << "Can't get a drive letter to test with.";
|
| - return;
|
| - }
|
| -
|
| - // Get the NT style path to that drive.
|
| - wchar_t device_path[MAX_PATH] = {'\0'};
|
| - ASSERT_TRUE(
|
| - ::QueryDosDevice(real_drive_letter.c_str(), device_path, MAX_PATH));
|
| - FilePath actual_device_path(device_path);
|
| - FilePath win32_path;
|
| -
|
| - // Run DevicePathToDriveLetterPath() on the NT style path we got from
|
| - // QueryDosDevice(). Expect the drive letter we started with.
|
| - ASSERT_TRUE(DevicePathToDriveLetterPath(actual_device_path, &win32_path));
|
| - ASSERT_EQ(real_drive_letter, win32_path.value());
|
| -
|
| - // Add some directories to the path. Expect those extra path componenets
|
| - // to be preserved.
|
| - FilePath kRelativePath(FPL("dir1\\dir2\\file.txt"));
|
| - ASSERT_TRUE(DevicePathToDriveLetterPath(
|
| - actual_device_path.Append(kRelativePath),
|
| - &win32_path));
|
| - EXPECT_EQ(FilePath(real_drive_letter + L"\\").Append(kRelativePath).value(),
|
| - win32_path.value());
|
| -
|
| - // Deform the real path so that it is invalid by removing the last four
|
| - // characters. The way windows names devices that are hard disks
|
| - // (\Device\HardDiskVolume${NUMBER}) guarantees that the string is longer
|
| - // than three characters. The only way the truncated string could be a
|
| - // real drive is if more than 10^3 disks are mounted:
|
| - // \Device\HardDiskVolume10000 would be truncated to \Device\HardDiskVolume1
|
| - // Check that DevicePathToDriveLetterPath fails.
|
| - int path_length = actual_device_path.value().length();
|
| - int new_length = path_length - 4;
|
| - ASSERT_LT(0, new_length);
|
| - FilePath prefix_of_real_device_path(
|
| - actual_device_path.value().substr(0, new_length));
|
| - ASSERT_FALSE(DevicePathToDriveLetterPath(prefix_of_real_device_path,
|
| - &win32_path));
|
| -
|
| - ASSERT_FALSE(DevicePathToDriveLetterPath(
|
| - prefix_of_real_device_path.Append(kRelativePath),
|
| - &win32_path));
|
| -
|
| - // Deform the real path so that it is invalid by adding some characters. For
|
| - // example, if C: maps to \Device\HardDiskVolume8, then we simulate a
|
| - // request for the drive letter whose native path is
|
| - // \Device\HardDiskVolume812345 . We assume such a device does not exist,
|
| - // because drives are numbered in order and mounting 112345 hard disks will
|
| - // never happen.
|
| - const FilePath::StringType kExtraChars = FPL("12345");
|
| -
|
| - FilePath real_device_path_plus_numbers(
|
| - actual_device_path.value() + kExtraChars);
|
| -
|
| - ASSERT_FALSE(DevicePathToDriveLetterPath(
|
| - real_device_path_plus_numbers,
|
| - &win32_path));
|
| -
|
| - ASSERT_FALSE(DevicePathToDriveLetterPath(
|
| - real_device_path_plus_numbers.Append(kRelativePath),
|
| - &win32_path));
|
| -}
|
| -
|
| -TEST_F(FileUtilTest, CreateTemporaryFileInDirLongPathTest) {
|
| - // Test that CreateTemporaryFileInDir() creates a path and returns a long path
|
| - // if it is available. This test requires that:
|
| - // - the filesystem at |temp_dir_| supports long filenames.
|
| - // - the account has FILE_LIST_DIRECTORY permission for all ancestor
|
| - // directories of |temp_dir_|.
|
| - const FilePath::CharType kLongDirName[] = FPL("A long path");
|
| - const FilePath::CharType kTestSubDirName[] = FPL("test");
|
| - FilePath long_test_dir = temp_dir_.path().Append(kLongDirName);
|
| - ASSERT_TRUE(CreateDirectory(long_test_dir));
|
| -
|
| - // kLongDirName is not a 8.3 component. So GetShortName() should give us a
|
| - // different short name.
|
| - WCHAR path_buffer[MAX_PATH];
|
| - DWORD path_buffer_length = GetShortPathName(long_test_dir.value().c_str(),
|
| - path_buffer, MAX_PATH);
|
| - ASSERT_LT(path_buffer_length, DWORD(MAX_PATH));
|
| - ASSERT_NE(DWORD(0), path_buffer_length);
|
| - FilePath short_test_dir(path_buffer);
|
| - ASSERT_STRNE(kLongDirName, short_test_dir.BaseName().value().c_str());
|
| -
|
| - FilePath temp_file;
|
| - ASSERT_TRUE(CreateTemporaryFileInDir(short_test_dir, &temp_file));
|
| - EXPECT_STREQ(kLongDirName, temp_file.DirName().BaseName().value().c_str());
|
| - EXPECT_TRUE(PathExists(temp_file));
|
| -
|
| - // Create a subdirectory of |long_test_dir| and make |long_test_dir|
|
| - // unreadable. We should still be able to create a temp file in the
|
| - // subdirectory, but we won't be able to determine the long path for it. This
|
| - // mimics the environment that some users run where their user profiles reside
|
| - // in a location where the don't have full access to the higher level
|
| - // directories. (Note that this assumption is true for NTFS, but not for some
|
| - // network file systems. E.g. AFS).
|
| - FilePath access_test_dir = long_test_dir.Append(kTestSubDirName);
|
| - ASSERT_TRUE(CreateDirectory(access_test_dir));
|
| - FilePermissionRestorer long_test_dir_restorer(long_test_dir);
|
| - ASSERT_TRUE(MakeFileUnreadable(long_test_dir));
|
| -
|
| - // Use the short form of the directory to create a temporary filename.
|
| - ASSERT_TRUE(CreateTemporaryFileInDir(
|
| - short_test_dir.Append(kTestSubDirName), &temp_file));
|
| - EXPECT_TRUE(PathExists(temp_file));
|
| - EXPECT_TRUE(short_test_dir.IsParent(temp_file.DirName()));
|
| -
|
| - // Check that the long path can't be determined for |temp_file|.
|
| - path_buffer_length = GetLongPathName(temp_file.value().c_str(),
|
| - path_buffer, MAX_PATH);
|
| - EXPECT_EQ(DWORD(0), path_buffer_length);
|
| -}
|
| -
|
| -#endif // defined(OS_WIN)
|
| -
|
| #if defined(OS_POSIX)
|
|
|
| TEST_F(FileUtilTest, CreateAndReadSymlinks) {
|
| @@ -846,57 +476,6 @@ TEST_F(FileUtilTest, ChangeDirectoryPermissionsAndEnumerate) {
|
|
|
| #endif // defined(OS_POSIX)
|
|
|
| -#if defined(OS_WIN)
|
| -// Tests that the Delete function works for wild cards, especially
|
| -// with the recursion flag. Also coincidentally tests PathExists.
|
| -// TODO(erikkay): see if anyone's actually using this feature of the API
|
| -TEST_F(FileUtilTest, DeleteWildCard) {
|
| - // Create a file and a directory
|
| - FilePath file_name = temp_dir_.path().Append(FPL("Test DeleteWildCard.txt"));
|
| - CreateTextFile(file_name, bogus_content);
|
| - ASSERT_TRUE(PathExists(file_name));
|
| -
|
| - FilePath subdir_path = temp_dir_.path().Append(FPL("DeleteWildCardDir"));
|
| - CreateDirectory(subdir_path);
|
| - ASSERT_TRUE(PathExists(subdir_path));
|
| -
|
| - // Create the wildcard path
|
| - FilePath directory_contents = temp_dir_.path();
|
| - directory_contents = directory_contents.Append(FPL("*"));
|
| -
|
| - // Delete non-recursively and check that only the file is deleted
|
| - EXPECT_TRUE(DeleteFile(directory_contents, false));
|
| - EXPECT_FALSE(PathExists(file_name));
|
| - EXPECT_TRUE(PathExists(subdir_path));
|
| -
|
| - // Delete recursively and make sure all contents are deleted
|
| - EXPECT_TRUE(DeleteFile(directory_contents, true));
|
| - EXPECT_FALSE(PathExists(file_name));
|
| - EXPECT_FALSE(PathExists(subdir_path));
|
| -}
|
| -
|
| -// TODO(erikkay): see if anyone's actually using this feature of the API
|
| -TEST_F(FileUtilTest, DeleteNonExistantWildCard) {
|
| - // Create a file and a directory
|
| - FilePath subdir_path =
|
| - temp_dir_.path().Append(FPL("DeleteNonExistantWildCard"));
|
| - CreateDirectory(subdir_path);
|
| - ASSERT_TRUE(PathExists(subdir_path));
|
| -
|
| - // Create the wildcard path
|
| - FilePath directory_contents = subdir_path;
|
| - directory_contents = directory_contents.Append(FPL("*"));
|
| -
|
| - // Delete non-recursively and check nothing got deleted
|
| - EXPECT_TRUE(DeleteFile(directory_contents, false));
|
| - EXPECT_TRUE(PathExists(subdir_path));
|
| -
|
| - // Delete recursively and check nothing got deleted
|
| - EXPECT_TRUE(DeleteFile(directory_contents, true));
|
| - EXPECT_TRUE(PathExists(subdir_path));
|
| -}
|
| -#endif
|
| -
|
| // Tests non-recursive Delete() for a directory.
|
| TEST_F(FileUtilTest, DeleteDirNonRecursive) {
|
| // Create a subdirectory and put a file and two directories inside.
|
| @@ -1370,10 +949,7 @@ TEST_F(FileUtilTest, CopyDirectoryWithTrailingSeparators) {
|
| dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt"));
|
|
|
| // Create from path with trailing separators.
|
| -#if defined(OS_WIN)
|
| - FilePath from_path =
|
| - temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir\\\\\\"));
|
| -#elif defined (OS_POSIX)
|
| +#if defined (OS_POSIX)
|
| FilePath from_path =
|
| temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir///"));
|
| #endif
|
| @@ -1389,42 +965,15 @@ TEST_F(FileUtilTest, CopyDirectoryWithTrailingSeparators) {
|
|
|
| // 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) {
|
| @@ -1611,68 +1160,6 @@ TEST_F(ReadOnlyFileUtilTest, TextContentsEqual) {
|
| EXPECT_TRUE(TextContentsEqual(blank_line_file, blank_line_crlf_file));
|
| }
|
|
|
| -// We don't need equivalent functionality outside of Windows.
|
| -#if defined(OS_WIN)
|
| -TEST_F(FileUtilTest, CopyAndDeleteDirectoryTest) {
|
| - // Create a directory
|
| - FilePath dir_name_from =
|
| - temp_dir_.path().Append(FILE_PATH_LITERAL("CopyAndDelete_From_Subdir"));
|
| - CreateDirectory(dir_name_from);
|
| - ASSERT_TRUE(PathExists(dir_name_from));
|
| -
|
| - // Create a file under the directory
|
| - FilePath file_name_from =
|
| - dir_name_from.Append(FILE_PATH_LITERAL("CopyAndDelete_Test_File.txt"));
|
| - CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle");
|
| - ASSERT_TRUE(PathExists(file_name_from));
|
| -
|
| - // Move the directory by using CopyAndDeleteDirectory
|
| - FilePath dir_name_to = temp_dir_.path().Append(
|
| - FILE_PATH_LITERAL("CopyAndDelete_To_Subdir"));
|
| - FilePath file_name_to =
|
| - dir_name_to.Append(FILE_PATH_LITERAL("CopyAndDelete_Test_File.txt"));
|
| -
|
| - ASSERT_FALSE(PathExists(dir_name_to));
|
| -
|
| - EXPECT_TRUE(internal::CopyAndDeleteDirectory(dir_name_from,
|
| - dir_name_to));
|
| -
|
| - // Check everything has been moved.
|
| - EXPECT_FALSE(PathExists(dir_name_from));
|
| - EXPECT_FALSE(PathExists(file_name_from));
|
| - EXPECT_TRUE(PathExists(dir_name_to));
|
| - EXPECT_TRUE(PathExists(file_name_to));
|
| -}
|
| -
|
| -TEST_F(FileUtilTest, GetTempDirTest) {
|
| - static const TCHAR* kTmpKey = _T("TMP");
|
| - static const TCHAR* kTmpValues[] = {
|
| - _T(""), _T("C:"), _T("C:\\"), _T("C:\\tmp"), _T("C:\\tmp\\")
|
| - };
|
| - // Save the original $TMP.
|
| - size_t original_tmp_size;
|
| - TCHAR* original_tmp;
|
| - ASSERT_EQ(0, ::_tdupenv_s(&original_tmp, &original_tmp_size, kTmpKey));
|
| - // original_tmp may be NULL.
|
| -
|
| - for (unsigned int i = 0; i < arraysize(kTmpValues); ++i) {
|
| - FilePath path;
|
| - ::_tputenv_s(kTmpKey, kTmpValues[i]);
|
| - GetTempDir(&path);
|
| - EXPECT_TRUE(path.IsAbsolute()) << "$TMP=" << kTmpValues[i] <<
|
| - " result=" << path.value();
|
| - }
|
| -
|
| - // Restore the original $TMP.
|
| - if (original_tmp) {
|
| - ::_tputenv_s(kTmpKey, original_tmp);
|
| - free(original_tmp);
|
| - } else {
|
| - ::_tputenv_s(kTmpKey, _T(""));
|
| - }
|
| -}
|
| -#endif // OS_WIN
|
| -
|
| TEST_F(FileUtilTest, CreateTemporaryFileTest) {
|
| FilePath temp_files[3];
|
| for (int i = 0; i < 3; i++) {
|
| @@ -1765,10 +1252,7 @@ TEST_F(FileUtilTest, GetHomeDirTest) {
|
| TEST_F(FileUtilTest, CreateDirectoryTest) {
|
| FilePath test_root =
|
| temp_dir_.path().Append(FILE_PATH_LITERAL("create_directory_test"));
|
| -#if defined(OS_WIN)
|
| - FilePath test_path =
|
| - test_root.Append(FILE_PATH_LITERAL("dir\\tree\\likely\\doesnt\\exist\\"));
|
| -#elif defined(OS_POSIX)
|
| +#if defined(OS_POSIX)
|
| FilePath test_path =
|
| test_root.Append(FILE_PATH_LITERAL("dir/tree/likely/doesnt/exist/"));
|
| #endif
|
| @@ -1805,15 +1289,6 @@ TEST_F(FileUtilTest, CreateDirectoryTest) {
|
| EXPECT_TRUE(CreateDirectory(
|
| FilePath(FilePath::kCurrentDirectory)));
|
| EXPECT_TRUE(CreateDirectory(top_level));
|
| -
|
| -#if defined(OS_WIN)
|
| - FilePath invalid_drive(FILE_PATH_LITERAL("o:\\"));
|
| - FilePath invalid_path =
|
| - invalid_drive.Append(FILE_PATH_LITERAL("some\\inaccessible\\dir"));
|
| - if (!PathExists(invalid_drive)) {
|
| - EXPECT_FALSE(CreateDirectory(invalid_path));
|
| - }
|
| -#endif
|
| }
|
|
|
| TEST_F(FileUtilTest, DetectDirectoryTest) {
|
| @@ -1935,48 +1410,6 @@ TEST_F(FileUtilTest, FileEnumeratorTest) {
|
| EXPECT_TRUE(c5.HasFile(dir2innerfile));
|
| EXPECT_EQ(5, c5.size());
|
|
|
| -#if defined(OS_WIN)
|
| - {
|
| - // Make dir1 point to dir2.
|
| - ReparsePoint reparse_point(dir1, dir2);
|
| - EXPECT_TRUE(reparse_point.IsValid());
|
| -
|
| - if ((win::GetVersion() >= win::VERSION_VISTA)) {
|
| - // There can be a delay for the enumeration code to see the change on
|
| - // the file system so skip this test for XP.
|
| - // Enumerate the reparse point.
|
| - FileEnumerator f6(dir1, true, FILES_AND_DIRECTORIES);
|
| - FindResultCollector c6(&f6);
|
| - FilePath inner2 = dir1.Append(FPL("inner"));
|
| - EXPECT_TRUE(c6.HasFile(inner2));
|
| - EXPECT_TRUE(c6.HasFile(inner2.Append(FPL("innerfile.txt"))));
|
| - EXPECT_TRUE(c6.HasFile(dir1.Append(FPL("dir2file.txt"))));
|
| - EXPECT_EQ(3, c6.size());
|
| - }
|
| -
|
| - // No changes for non recursive operation.
|
| - FileEnumerator f7(temp_dir_.path(), false, FILES_AND_DIRECTORIES);
|
| - FindResultCollector c7(&f7);
|
| - EXPECT_TRUE(c7.HasFile(dir2));
|
| - EXPECT_TRUE(c7.HasFile(dir2));
|
| - EXPECT_TRUE(c7.HasFile(file1));
|
| - EXPECT_TRUE(c7.HasFile(file2_abs));
|
| - EXPECT_EQ(4, c7.size());
|
| -
|
| - // Should not enumerate inside dir1 when using recursion.
|
| - FileEnumerator f8(temp_dir_.path(), true, FILES_AND_DIRECTORIES);
|
| - FindResultCollector c8(&f8);
|
| - EXPECT_TRUE(c8.HasFile(dir1));
|
| - EXPECT_TRUE(c8.HasFile(dir2));
|
| - EXPECT_TRUE(c8.HasFile(file1));
|
| - EXPECT_TRUE(c8.HasFile(file2_abs));
|
| - EXPECT_TRUE(c8.HasFile(dir2file));
|
| - EXPECT_TRUE(c8.HasFile(dir2inner));
|
| - EXPECT_TRUE(c8.HasFile(dir2innerfile));
|
| - EXPECT_EQ(7, c8.size());
|
| - }
|
| -#endif
|
| -
|
| // Make sure the destructor closes the find handle while in the middle of a
|
| // query to allow TearDown to delete the directory.
|
| FileEnumerator f9(temp_dir_.path(), true, FILES_AND_DIRECTORIES);
|
|
|