diff options
author | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-08 21:43:30 +0000 |
---|---|---|
committer | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-08 21:43:30 +0000 |
commit | 7600d0b2d5e37b211280d5109a6b726644d6be76 (patch) | |
tree | 4ba2cb5383bb9ef5f610aeffe5d4455149da683b /base | |
parent | a4f7378f973b38400f133958842eb36db0b61dcb (diff) | |
download | chromium_src-7600d0b2d5e37b211280d5109a6b726644d6be76.zip chromium_src-7600d0b2d5e37b211280d5109a6b726644d6be76.tar.gz chromium_src-7600d0b2d5e37b211280d5109a6b726644d6be76.tar.bz2 |
Revert 239400 "Revert 239280 "Move more file_util functions to b..."
Broke all bots 9_9
> Revert 239280 "Move more file_util functions to base namespace."
>
> dbus_unittests started fialing on Linux Tests (dbg)(2) and Linux Tests (dbg)(2)(32).
> This CL is the only in the intersection of CLs in the first failing build on
> the two builders, so giving a speculative revert a try (rlarocque already
> tried a clobber, it didn't help).
>
> http://build.chromium.org/p/chromium.linux/builders/Linux%20Tests%20%28dbg%29%282%29/builds/41806
> http://build.chromium.org/p/chromium.linux/builders/Linux%20Tests%20%28dbg%29%282%29%2832%29/builds/8544
>
>
> > Move more file_util functions to base namespace.
> >
> > TBR=sky
> >
> > Review URL: https://codereview.chromium.org/109043002
>
> TBR=brettw@chromium.org
>
> Review URL: https://codereview.chromium.org/105823009
TBR=thakis@chromium.org
Review URL: https://codereview.chromium.org/100923007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@239401 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/event_recorder_win.cc | 12 | ||||
-rw-r--r-- | base/file_util.cc | 23 | ||||
-rw-r--r-- | base/file_util.h | 19 | ||||
-rw-r--r-- | base/file_util_posix.cc | 53 | ||||
-rw-r--r-- | base/file_util_unittest.cc | 140 | ||||
-rw-r--r-- | base/file_util_win.cc | 36 | ||||
-rw-r--r-- | base/files/file_util_proxy_unittest.cc | 6 | ||||
-rw-r--r-- | base/memory/shared_memory_posix.cc | 2 | ||||
-rw-r--r-- | base/nix/mime_util_xdg.cc | 4 | ||||
-rw-r--r-- | base/test/gtest_xml_util.cc | 4 | ||||
-rw-r--r-- | base/test/launcher/test_results_tracker.cc | 2 | ||||
-rw-r--r-- | base/test/perf_log.cc | 4 | ||||
-rw-r--r-- | base/win/shortcut_unittest.cc | 6 |
13 files changed, 147 insertions, 164 deletions
diff --git a/base/event_recorder_win.cc b/base/event_recorder_win.cc index 11bf0f0..39c4220 100644 --- a/base/event_recorder_win.cc +++ b/base/event_recorder_win.cc @@ -49,7 +49,7 @@ bool EventRecorder::StartRecording(const FilePath& filename) { // Open the recording file. DCHECK(!file_); - file_ = file_util::OpenFile(filename, "wb+"); + file_ = OpenFile(filename, "wb+"); if (!file_) { DLOG(ERROR) << "EventRecorder could not open log file"; return false; @@ -63,7 +63,7 @@ bool EventRecorder::StartRecording(const FilePath& filename) { GetModuleHandle(NULL), 0); if (!journal_hook_) { DLOG(ERROR) << "EventRecorder Record Hook failed"; - file_util::CloseFile(file_); + CloseFile(file_); return false; } @@ -84,7 +84,7 @@ void EventRecorder::StopRecording() { ::timeEndPeriod(1); DCHECK(file_ != NULL); - file_util::CloseFile(file_); + CloseFile(file_); file_ = NULL; journal_hook_ = NULL; @@ -100,7 +100,7 @@ bool EventRecorder::StartPlayback(const FilePath& filename) { // Open the recording file. DCHECK(!file_); - file_ = file_util::OpenFile(filename, "rb"); + file_ = OpenFile(filename, "rb"); if (!file_) { DLOG(ERROR) << "EventRecorder Playback could not open log file"; return false; @@ -108,7 +108,7 @@ bool EventRecorder::StartPlayback(const FilePath& filename) { // Read the first event from the record. if (fread(&playback_msg_, sizeof(EVENTMSG), 1, file_) != 1) { DLOG(ERROR) << "EventRecorder Playback has no records!"; - file_util::CloseFile(file_); + CloseFile(file_); return false; } @@ -150,7 +150,7 @@ void EventRecorder::StopPlayback() { } DCHECK(file_ != NULL); - file_util::CloseFile(file_); + CloseFile(file_); file_ = NULL; ::timeEndPeriod(1); diff --git a/base/file_util.cc b/base/file_util.cc index 8bcf1a4..1575a07 100644 --- a/base/file_util.cc +++ b/base/file_util.cc @@ -129,7 +129,7 @@ bool TextContentsEqual(const FilePath& filename1, const FilePath& filename2) { bool ReadFileToString(const FilePath& path, std::string* contents) { if (path.ReferencesParent()) return false; - FILE* file = file_util::OpenFile(path, "rb"); + FILE* file = OpenFile(path, "rb"); if (!file) { return false; } @@ -140,7 +140,7 @@ bool ReadFileToString(const FilePath& path, std::string* contents) { if (contents) contents->append(buf, len); } - file_util::CloseFile(file); + CloseFile(file); return true; } @@ -194,16 +194,6 @@ bool TouchFile(const FilePath& path, return false; } -} // namespace base - -// ----------------------------------------------------------------------------- - -namespace file_util { - -using base::FileEnumerator; -using base::FilePath; -using base::kMaxUniqueFiles; - bool CloseFile(FILE* file) { if (file == NULL) return true; @@ -228,6 +218,15 @@ bool TruncateFile(FILE* file) { return true; } +} // namespace base + +// ----------------------------------------------------------------------------- + +namespace file_util { + +using base::FilePath; +using base::kMaxUniqueFiles; + int GetUniquePathNumber( const FilePath& path, const FilePath::StringType& suffix) { diff --git a/base/file_util.h b/base/file_util.h index 1fea6e8..3f892e3 100644 --- a/base/file_util.h +++ b/base/file_util.h @@ -299,19 +299,8 @@ BASE_EXPORT bool TouchFile(const FilePath& path, const Time& last_accessed, const Time& last_modified); -} // namespace base - -// ----------------------------------------------------------------------------- - -namespace file_util { - -#if defined(OS_POSIX) -// Store inode number of |path| in |inode|. Return true on success. -BASE_EXPORT bool GetInode(const base::FilePath& path, ino_t* inode); -#endif - // Wrapper for fopen-like calls. Returns non-NULL FILE* on success. -BASE_EXPORT FILE* OpenFile(const base::FilePath& filename, const char* mode); +BASE_EXPORT FILE* OpenFile(const FilePath& filename, const char* mode); // Closes file opened by OpenFile. Returns true on success. BASE_EXPORT bool CloseFile(FILE* file); @@ -324,6 +313,12 @@ BASE_EXPORT bool TruncateFile(FILE* file); // the number of read bytes, or -1 on error. BASE_EXPORT int ReadFile(const base::FilePath& filename, char* data, int size); +} // namespace base + +// ----------------------------------------------------------------------------- + +namespace file_util { + // Writes the given buffer into the file, overwriting any data that was // previously there. Returns the number of bytes written, or -1 on error. BASE_EXPORT int WriteFile(const base::FilePath& filename, const char* data, diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc index fdf196e..ddcd5dd 100644 --- a/base/file_util_posix.cc +++ b/base/file_util_posix.cc @@ -689,6 +689,27 @@ bool GetFileInfo(const FilePath& file_path, PlatformFileInfo* results) { return true; } +FILE* OpenFile(const FilePath& filename, const char* mode) { + ThreadRestrictions::AssertIOAllowed(); + FILE* result = NULL; + do { + result = fopen(filename.value().c_str(), mode); + } while (!result && errno == EINTR); + return result; +} + +int ReadFile(const FilePath& filename, char* data, int size) { + ThreadRestrictions::AssertIOAllowed(); + int fd = HANDLE_EINTR(open(filename.value().c_str(), O_RDONLY)); + if (fd < 0) + return -1; + + ssize_t bytes_read = HANDLE_EINTR(read(fd, data, size)); + if (int ret = IGNORE_EINTR(close(fd)) < 0) + return ret; + return bytes_read; +} + } // namespace base // ----------------------------------------------------------------------------- @@ -723,42 +744,10 @@ base::FilePath MakeUniqueDirectory(const base::FilePath& path) { return base::FilePath(); } -bool GetInode(const FilePath& path, ino_t* inode) { - base::ThreadRestrictions::AssertIOAllowed(); // For call to stat(). - struct stat buffer; - int result = stat(path.value().c_str(), &buffer); - if (result < 0) - return false; - - *inode = buffer.st_ino; - return true; -} - FILE* OpenFile(const std::string& filename, const char* mode) { return OpenFile(FilePath(filename), mode); } -FILE* OpenFile(const FilePath& filename, const char* mode) { - base::ThreadRestrictions::AssertIOAllowed(); - FILE* result = NULL; - do { - result = fopen(filename.value().c_str(), mode); - } while (!result && errno == EINTR); - return result; -} - -int ReadFile(const FilePath& filename, char* data, int size) { - base::ThreadRestrictions::AssertIOAllowed(); - int fd = HANDLE_EINTR(open(filename.value().c_str(), O_RDONLY)); - if (fd < 0) - return -1; - - ssize_t bytes_read = HANDLE_EINTR(read(fd, data, size)); - if (int ret = IGNORE_EINTR(close(fd)) < 0) - return ret; - return bytes_read; -} - int WriteFile(const FilePath& filename, const char* data, int size) { base::ThreadRestrictions::AssertIOAllowed(); int fd = HANDLE_EINTR(creat(filename.value().c_str(), 0666)); diff --git a/base/file_util_unittest.cc b/base/file_util_unittest.cc index 4ffa4ba..b65e171 100644 --- a/base/file_util_unittest.cc +++ b/base/file_util_unittest.cc @@ -254,7 +254,7 @@ TEST_F(FileUtilTest, FileAndDirectorySize) { EXPECT_EQ(20ll, size_f1); FilePath subdir_path = temp_dir_.path().Append(FPL("Level2")); - base::CreateDirectory(subdir_path); + CreateDirectory(subdir_path); FilePath file_02 = subdir_path.Append(FPL("The file 02.txt")); CreateTextFile(file_02, L"123456789012345678901234567890"); @@ -263,7 +263,7 @@ TEST_F(FileUtilTest, FileAndDirectorySize) { EXPECT_EQ(30ll, size_f2); FilePath subsubdir_path = subdir_path.Append(FPL("Level3")); - base::CreateDirectory(subsubdir_path); + CreateDirectory(subsubdir_path); FilePath file_03 = subsubdir_path.Append(FPL("The file 03.txt")); CreateTextFile(file_03, L"123"); @@ -278,7 +278,7 @@ TEST_F(FileUtilTest, NormalizeFilePathBasic) { FilePath file_a_path = temp_dir_.path().Append(FPL("file_a")); FilePath dir_path = temp_dir_.path().Append(FPL("dir")); FilePath file_b_path = dir_path.Append(FPL("file_b")); - base::CreateDirectory(dir_path); + CreateDirectory(dir_path); FilePath normalized_file_a_path, normalized_file_b_path; ASSERT_FALSE(PathExists(file_a_path)); @@ -318,10 +318,10 @@ TEST_F(FileUtilTest, NormalizeFilePathReparsePoints) { // |-> to_sub_long (reparse point to temp_dir\sub_a\long_name_\sub_long) FilePath base_a = temp_dir_.path().Append(FPL("base_a")); - ASSERT_TRUE(base::CreateDirectory(base_a)); + ASSERT_TRUE(CreateDirectory(base_a)); FilePath sub_a = base_a.Append(FPL("sub_a")); - ASSERT_TRUE(base::CreateDirectory(sub_a)); + ASSERT_TRUE(CreateDirectory(sub_a)); FilePath file_txt = sub_a.Append(FPL("file.txt")); CreateTextFile(file_txt, bogus_content); @@ -349,26 +349,26 @@ TEST_F(FileUtilTest, NormalizeFilePathReparsePoints) { ASSERT_EQ(MAX_PATH - kCreateDirLimit, deep_file.value().length()); FilePath sub_long = deep_file.DirName(); - ASSERT_TRUE(base::CreateDirectory(sub_long)); + ASSERT_TRUE(CreateDirectory(sub_long)); CreateTextFile(deep_file, bogus_content); FilePath base_b = temp_dir_.path().Append(FPL("base_b")); - ASSERT_TRUE(base::CreateDirectory(base_b)); + ASSERT_TRUE(CreateDirectory(base_b)); FilePath to_sub_a = base_b.Append(FPL("to_sub_a")); - ASSERT_TRUE(base::CreateDirectory(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(base::CreateDirectory(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(base::CreateDirectory(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()); @@ -487,7 +487,7 @@ TEST_F(FileUtilTest, DevicePathToDriveLetter) { TEST_F(FileUtilTest, GetPlatformFileInfoForDirectory) { FilePath empty_dir = temp_dir_.path().Append(FPL("gpfi_test")); - ASSERT_TRUE(base::CreateDirectory(empty_dir)); + ASSERT_TRUE(CreateDirectory(empty_dir)); win::ScopedHandle dir( ::CreateFile(empty_dir.value().c_str(), FILE_ALL_ACCESS, @@ -513,7 +513,7 @@ TEST_F(FileUtilTest, CreateTemporaryFileInDirLongPathTest) { 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(base::CreateDirectory(long_test_dir)); + ASSERT_TRUE(CreateDirectory(long_test_dir)); // kLongDirName is not a 8.3 component. So GetShortName() should give us a // different short name. @@ -526,7 +526,7 @@ TEST_F(FileUtilTest, CreateTemporaryFileInDirLongPathTest) { ASSERT_STRNE(kLongDirName, short_test_dir.BaseName().value().c_str()); FilePath temp_file; - ASSERT_TRUE(base::CreateTemporaryFileInDir(short_test_dir, &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)); @@ -538,12 +538,12 @@ TEST_F(FileUtilTest, CreateTemporaryFileInDirLongPathTest) { // 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(base::CreateDirectory(access_test_dir)); + ASSERT_TRUE(CreateDirectory(access_test_dir)); file_util::PermissionRestorer long_test_dir_restorer(long_test_dir); ASSERT_TRUE(file_util::MakeFileUnreadable(long_test_dir)); // Use the short form of the directory to create a temporary filename. - ASSERT_TRUE(base::CreateTemporaryFileInDir( + ASSERT_TRUE(CreateTemporaryFileInDir( short_test_dir.Append(kTestSubDirName), &temp_file)); EXPECT_TRUE(PathExists(temp_file)); EXPECT_TRUE(short_test_dir.IsParent(temp_file.DirName())); @@ -578,7 +578,7 @@ TEST_F(FileUtilTest, CreateAndReadSymlinks) { // Link to a directory. link_from = temp_dir_.path().Append(FPL("from_dir")); link_to = temp_dir_.path().Append(FPL("to_dir")); - ASSERT_TRUE(base::CreateDirectory(link_to)); + ASSERT_TRUE(CreateDirectory(link_to)); ASSERT_TRUE(CreateSymbolicLink(link_to, link_from)) << "Failed to create directory symlink."; @@ -613,7 +613,7 @@ TEST_F(FileUtilTest, NormalizeFilePathSymlinks) { // Link to a directory. link_from = temp_dir_.path().Append(FPL("from_dir")); link_to = temp_dir_.path().Append(FPL("to_dir")); - ASSERT_TRUE(base::CreateDirectory(link_to)); + ASSERT_TRUE(CreateDirectory(link_to)); ASSERT_TRUE(CreateSymbolicLink(link_to, link_from)) << "Failed to create directory symlink."; @@ -729,7 +729,7 @@ TEST_F(FileUtilTest, ChangeFilePermissionsAndRead) { EXPECT_TRUE(GetPosixFilePermissions(file_name, &mode)); EXPECT_FALSE(mode & FILE_PERMISSION_READ_BY_USER); // Make sure the file can't be read. - EXPECT_EQ(-1, file_util::ReadFile(file_name, buffer, buffer_size)); + EXPECT_EQ(-1, ReadFile(file_name, buffer, buffer_size)); // Give the read permission. EXPECT_TRUE(SetPosixFilePermissions(file_name, FILE_PERMISSION_READ_BY_USER)); @@ -737,7 +737,7 @@ TEST_F(FileUtilTest, ChangeFilePermissionsAndRead) { EXPECT_TRUE(mode & FILE_PERMISSION_READ_BY_USER); // Make sure the file can be read. EXPECT_EQ(static_cast<int>(kData.length()), - file_util::ReadFile(file_name, buffer, buffer_size)); + ReadFile(file_name, buffer, buffer_size)); // Delete the file. EXPECT_TRUE(DeleteFile(file_name, false)); @@ -792,7 +792,7 @@ TEST_F(FileUtilTest, ChangeDirectoryPermissionsAndEnumerate) { // Create a directory path. FilePath subdir_path = temp_dir_.path().Append(FPL("PermissionTest1")); - base::CreateDirectory(subdir_path); + CreateDirectory(subdir_path); ASSERT_TRUE(PathExists(subdir_path)); // Create a dummy file to enumerate. @@ -849,7 +849,7 @@ TEST_F(FileUtilTest, DeleteWildCard) { ASSERT_TRUE(PathExists(file_name)); FilePath subdir_path = temp_dir_.path().Append(FPL("DeleteWildCardDir")); - base::CreateDirectory(subdir_path); + CreateDirectory(subdir_path); ASSERT_TRUE(PathExists(subdir_path)); // Create the wildcard path @@ -872,7 +872,7 @@ TEST_F(FileUtilTest, DeleteNonExistantWildCard) { // Create a file and a directory FilePath subdir_path = temp_dir_.path().Append(FPL("DeleteNonExistantWildCard")); - base::CreateDirectory(subdir_path); + CreateDirectory(subdir_path); ASSERT_TRUE(PathExists(subdir_path)); // Create the wildcard path @@ -893,7 +893,7 @@ TEST_F(FileUtilTest, DeleteNonExistantWildCard) { TEST_F(FileUtilTest, DeleteDirNonRecursive) { // Create a subdirectory and put a file and two directories inside. FilePath test_subdir = temp_dir_.path().Append(FPL("DeleteDirNonRecursive")); - base::CreateDirectory(test_subdir); + CreateDirectory(test_subdir); ASSERT_TRUE(PathExists(test_subdir)); FilePath file_name = test_subdir.Append(FPL("Test DeleteDir.txt")); @@ -901,11 +901,11 @@ TEST_F(FileUtilTest, DeleteDirNonRecursive) { ASSERT_TRUE(PathExists(file_name)); FilePath subdir_path1 = test_subdir.Append(FPL("TestSubDir1")); - base::CreateDirectory(subdir_path1); + CreateDirectory(subdir_path1); ASSERT_TRUE(PathExists(subdir_path1)); FilePath subdir_path2 = test_subdir.Append(FPL("TestSubDir2")); - base::CreateDirectory(subdir_path2); + CreateDirectory(subdir_path2); ASSERT_TRUE(PathExists(subdir_path2)); // Delete non-recursively and check that the empty dir got deleted @@ -923,7 +923,7 @@ TEST_F(FileUtilTest, DeleteDirNonRecursive) { TEST_F(FileUtilTest, DeleteDirRecursive) { // Create a subdirectory and put a file and two directories inside. FilePath test_subdir = temp_dir_.path().Append(FPL("DeleteDirRecursive")); - base::CreateDirectory(test_subdir); + CreateDirectory(test_subdir); ASSERT_TRUE(PathExists(test_subdir)); FilePath file_name = test_subdir.Append(FPL("Test DeleteDirRecursive.txt")); @@ -931,11 +931,11 @@ TEST_F(FileUtilTest, DeleteDirRecursive) { ASSERT_TRUE(PathExists(file_name)); FilePath subdir_path1 = test_subdir.Append(FPL("TestSubDir1")); - base::CreateDirectory(subdir_path1); + CreateDirectory(subdir_path1); ASSERT_TRUE(PathExists(subdir_path1)); FilePath subdir_path2 = test_subdir.Append(FPL("TestSubDir2")); - base::CreateDirectory(subdir_path2); + CreateDirectory(subdir_path2); ASSERT_TRUE(PathExists(subdir_path2)); // Delete recursively and check that the empty dir got deleted @@ -999,7 +999,7 @@ TEST_F(FileUtilTest, MoveFileDirExists) { // The destination directory FilePath dir_name_to = temp_dir_.path().Append(FILE_PATH_LITERAL("Destination")); - base::CreateDirectory(dir_name_to); + CreateDirectory(dir_name_to); ASSERT_TRUE(PathExists(dir_name_to)); EXPECT_FALSE(Move(file_name_from, dir_name_to)); @@ -1010,7 +1010,7 @@ TEST_F(FileUtilTest, MoveNew) { // Create a directory FilePath dir_name_from = temp_dir_.path().Append(FILE_PATH_LITERAL("Move_From_Subdir")); - base::CreateDirectory(dir_name_from); + CreateDirectory(dir_name_from); ASSERT_TRUE(PathExists(dir_name_from)); // Create a file under the directory @@ -1051,7 +1051,7 @@ TEST_F(FileUtilTest, MoveExist) { // Create a directory FilePath dir_name_from = temp_dir_.path().Append(FILE_PATH_LITERAL("Move_From_Subdir")); - base::CreateDirectory(dir_name_from); + CreateDirectory(dir_name_from); ASSERT_TRUE(PathExists(dir_name_from)); // Create a file under the directory @@ -1070,7 +1070,7 @@ TEST_F(FileUtilTest, MoveExist) { dir_name_to.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); // Create the destination directory. - base::CreateDirectory(dir_name_exists); + CreateDirectory(dir_name_exists); ASSERT_TRUE(PathExists(dir_name_exists)); EXPECT_TRUE(Move(dir_name_from, dir_name_to)); @@ -1086,7 +1086,7 @@ TEST_F(FileUtilTest, CopyDirectoryRecursivelyNew) { // Create a directory. FilePath dir_name_from = temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); - base::CreateDirectory(dir_name_from); + CreateDirectory(dir_name_from); ASSERT_TRUE(PathExists(dir_name_from)); // Create a file under the directory. @@ -1098,7 +1098,7 @@ TEST_F(FileUtilTest, CopyDirectoryRecursivelyNew) { // Create a subdirectory. FilePath subdir_name_from = dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); - base::CreateDirectory(subdir_name_from); + CreateDirectory(subdir_name_from); ASSERT_TRUE(PathExists(subdir_name_from)); // Create a file under the subdirectory. @@ -1136,7 +1136,7 @@ TEST_F(FileUtilTest, CopyDirectoryRecursivelyExists) { // Create a directory. FilePath dir_name_from = temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); - base::CreateDirectory(dir_name_from); + CreateDirectory(dir_name_from); ASSERT_TRUE(PathExists(dir_name_from)); // Create a file under the directory. @@ -1148,7 +1148,7 @@ TEST_F(FileUtilTest, CopyDirectoryRecursivelyExists) { // Create a subdirectory. FilePath subdir_name_from = dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); - base::CreateDirectory(subdir_name_from); + CreateDirectory(subdir_name_from); ASSERT_TRUE(PathExists(subdir_name_from)); // Create a file under the subdirectory. @@ -1171,7 +1171,7 @@ TEST_F(FileUtilTest, CopyDirectoryRecursivelyExists) { subdir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); // Create the destination directory. - base::CreateDirectory(dir_name_exists); + CreateDirectory(dir_name_exists); ASSERT_TRUE(PathExists(dir_name_exists)); EXPECT_TRUE(CopyDirectory(dir_name_from, dir_name_exists, true)); @@ -1191,7 +1191,7 @@ TEST_F(FileUtilTest, CopyDirectoryNew) { // Create a directory. FilePath dir_name_from = temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); - base::CreateDirectory(dir_name_from); + CreateDirectory(dir_name_from); ASSERT_TRUE(PathExists(dir_name_from)); // Create a file under the directory. @@ -1203,7 +1203,7 @@ TEST_F(FileUtilTest, CopyDirectoryNew) { // Create a subdirectory. FilePath subdir_name_from = dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); - base::CreateDirectory(subdir_name_from); + CreateDirectory(subdir_name_from); ASSERT_TRUE(PathExists(subdir_name_from)); // Create a file under the subdirectory. @@ -1238,7 +1238,7 @@ TEST_F(FileUtilTest, CopyDirectoryExists) { // Create a directory. FilePath dir_name_from = temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); - base::CreateDirectory(dir_name_from); + CreateDirectory(dir_name_from); ASSERT_TRUE(PathExists(dir_name_from)); // Create a file under the directory. @@ -1250,7 +1250,7 @@ TEST_F(FileUtilTest, CopyDirectoryExists) { // Create a subdirectory. FilePath subdir_name_from = dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); - base::CreateDirectory(subdir_name_from); + CreateDirectory(subdir_name_from); ASSERT_TRUE(PathExists(subdir_name_from)); // Create a file under the subdirectory. @@ -1268,7 +1268,7 @@ TEST_F(FileUtilTest, CopyDirectoryExists) { dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); // Create the destination directory. - base::CreateDirectory(dir_name_to); + CreateDirectory(dir_name_to); ASSERT_TRUE(PathExists(dir_name_to)); EXPECT_TRUE(CopyDirectory(dir_name_from, dir_name_to, false)); @@ -1331,7 +1331,7 @@ TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToExistingDirectory) { // The destination FilePath dir_name_to = temp_dir_.path().Append(FILE_PATH_LITERAL("Destination")); - base::CreateDirectory(dir_name_to); + CreateDirectory(dir_name_to); ASSERT_TRUE(PathExists(dir_name_to)); FilePath file_name_to = dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); @@ -1346,7 +1346,7 @@ TEST_F(FileUtilTest, CopyDirectoryWithTrailingSeparators) { // Create a directory. FilePath dir_name_from = temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); - base::CreateDirectory(dir_name_from); + CreateDirectory(dir_name_from); ASSERT_TRUE(PathExists(dir_name_from)); // Create a file under the directory. @@ -1383,7 +1383,7 @@ TEST_F(FileUtilTest, CopyFile) { // Create a directory FilePath dir_name_from = temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); - base::CreateDirectory(dir_name_from); + CreateDirectory(dir_name_from); ASSERT_TRUE(PathExists(dir_name_from)); // Create a file under the directory @@ -1518,7 +1518,7 @@ TEST_F(FileUtilTest, CopyAndDeleteDirectoryTest) { // Create a directory FilePath dir_name_from = temp_dir_.path().Append(FILE_PATH_LITERAL("CopyAndDelete_From_Subdir")); - base::CreateDirectory(dir_name_from); + CreateDirectory(dir_name_from); ASSERT_TRUE(PathExists(dir_name_from)); // Create a file under the directory @@ -1559,7 +1559,7 @@ TEST_F(FileUtilTest, GetTempDirTest) { for (unsigned int i = 0; i < arraysize(kTmpValues); ++i) { FilePath path; ::_tputenv_s(kTmpKey, kTmpValues[i]); - base::GetTempDir(&path); + GetTempDir(&path); EXPECT_TRUE(path.IsAbsolute()) << "$TMP=" << kTmpValues[i] << " result=" << path.value(); } @@ -1577,7 +1577,7 @@ TEST_F(FileUtilTest, GetTempDirTest) { TEST_F(FileUtilTest, CreateTemporaryFileTest) { FilePath temp_files[3]; for (int i = 0; i < 3; i++) { - ASSERT_TRUE(base::CreateTemporaryFile(&(temp_files[i]))); + ASSERT_TRUE(CreateTemporaryFile(&(temp_files[i]))); EXPECT_TRUE(PathExists(temp_files[i])); EXPECT_FALSE(DirectoryExists(temp_files[i])); } @@ -1594,7 +1594,7 @@ TEST_F(FileUtilTest, CreateAndOpenTemporaryFileTest) { // Create; make sure they are open and exist. for (i = 0; i < 3; ++i) { - fps[i] = base::CreateAndOpenTemporaryFile(&(names[i])); + fps[i] = CreateAndOpenTemporaryFile(&(names[i])); ASSERT_TRUE(fps[i]); EXPECT_TRUE(PathExists(names[i])); } @@ -1606,21 +1606,21 @@ TEST_F(FileUtilTest, CreateAndOpenTemporaryFileTest) { // Close and delete. for (i = 0; i < 3; ++i) { - EXPECT_TRUE(file_util::CloseFile(fps[i])); + EXPECT_TRUE(CloseFile(fps[i])); EXPECT_TRUE(DeleteFile(names[i], false)); } } TEST_F(FileUtilTest, CreateNewTempDirectoryTest) { FilePath temp_dir; - ASSERT_TRUE(base::CreateNewTempDirectory(FilePath::StringType(), &temp_dir)); + ASSERT_TRUE(CreateNewTempDirectory(FilePath::StringType(), &temp_dir)); EXPECT_TRUE(PathExists(temp_dir)); EXPECT_TRUE(DeleteFile(temp_dir, false)); } TEST_F(FileUtilTest, CreateNewTemporaryDirInDirTest) { FilePath new_dir; - ASSERT_TRUE(base::CreateTemporaryDirInDir( + ASSERT_TRUE(CreateTemporaryDirInDir( temp_dir_.path(), FILE_PATH_LITERAL("CreateNewTemporaryDirInDirTest"), &new_dir)); @@ -1647,17 +1647,17 @@ TEST_F(FileUtilTest, CreateDirectoryTest) { #endif EXPECT_FALSE(PathExists(test_path)); - EXPECT_TRUE(base::CreateDirectory(test_path)); + EXPECT_TRUE(CreateDirectory(test_path)); EXPECT_TRUE(PathExists(test_path)); // CreateDirectory returns true if the DirectoryExists returns true. - EXPECT_TRUE(base::CreateDirectory(test_path)); + EXPECT_TRUE(CreateDirectory(test_path)); // Doesn't work to create it on top of a non-dir test_path = test_path.Append(FILE_PATH_LITERAL("foobar.txt")); EXPECT_FALSE(PathExists(test_path)); CreateTextFile(test_path, L"test file"); EXPECT_TRUE(PathExists(test_path)); - EXPECT_FALSE(base::CreateDirectory(test_path)); + EXPECT_FALSE(CreateDirectory(test_path)); EXPECT_TRUE(DeleteFile(test_root, true)); EXPECT_FALSE(PathExists(test_root)); @@ -1675,16 +1675,16 @@ TEST_F(FileUtilTest, CreateDirectoryTest) { // Given these assumptions hold, it should be safe to // test that "creating" these directories succeeds. - EXPECT_TRUE(base::CreateDirectory( + EXPECT_TRUE(CreateDirectory( FilePath(FilePath::kCurrentDirectory))); - EXPECT_TRUE(base::CreateDirectory(top_level)); + 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(base::CreateDirectory(invalid_path)); + EXPECT_FALSE(CreateDirectory(invalid_path)); } #endif } @@ -1694,7 +1694,7 @@ TEST_F(FileUtilTest, DetectDirectoryTest) { FilePath test_root = temp_dir_.path().Append(FILE_PATH_LITERAL("detect_directory_test")); EXPECT_FALSE(PathExists(test_root)); - EXPECT_TRUE(base::CreateDirectory(test_root)); + EXPECT_TRUE(CreateDirectory(test_root)); EXPECT_TRUE(PathExists(test_root)); EXPECT_TRUE(DirectoryExists(test_root)); // Check a file @@ -1724,11 +1724,11 @@ TEST_F(FileUtilTest, FileEnumeratorTest) { // create the directories FilePath dir1 = temp_dir_.path().Append(FPL("dir1")); - EXPECT_TRUE(base::CreateDirectory(dir1)); + EXPECT_TRUE(CreateDirectory(dir1)); FilePath dir2 = temp_dir_.path().Append(FPL("dir2")); - EXPECT_TRUE(base::CreateDirectory(dir2)); + EXPECT_TRUE(CreateDirectory(dir2)); FilePath dir2inner = dir2.Append(FPL("inner")); - EXPECT_TRUE(base::CreateDirectory(dir2inner)); + EXPECT_TRUE(CreateDirectory(dir2inner)); // create the files FilePath dir2file = dir2.Append(FPL("dir2file.txt")); @@ -1814,7 +1814,7 @@ TEST_F(FileUtilTest, FileEnumeratorTest) { ReparsePoint reparse_point(dir1, dir2); EXPECT_TRUE(reparse_point.IsValid()); - if ((win::GetVersion() >= base::win::VERSION_VISTA)) { + 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. @@ -1865,13 +1865,13 @@ TEST_F(FileUtilTest, AppendToFile) { if (PathExists(data_dir)) { ASSERT_TRUE(DeleteFile(data_dir, true)); } - ASSERT_TRUE(base::CreateDirectory(data_dir)); + ASSERT_TRUE(CreateDirectory(data_dir)); // Create a fresh, empty copy of this directory. if (PathExists(data_dir)) { ASSERT_TRUE(DeleteFile(data_dir, true)); } - ASSERT_TRUE(base::CreateDirectory(data_dir)); + ASSERT_TRUE(CreateDirectory(data_dir)); FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt"))); std::string data("hello"); @@ -1925,15 +1925,15 @@ TEST_F(FileUtilTest, IsDirectoryEmpty) { ASSERT_FALSE(PathExists(empty_dir)); - ASSERT_TRUE(base::CreateDirectory(empty_dir)); + ASSERT_TRUE(CreateDirectory(empty_dir)); - EXPECT_TRUE(base::IsDirectoryEmpty(empty_dir)); + EXPECT_TRUE(IsDirectoryEmpty(empty_dir)); FilePath foo(empty_dir.Append(FILE_PATH_LITERAL("foo.txt"))); std::string bar("baz"); ASSERT_TRUE(file_util::WriteFile(foo, bar.c_str(), bar.length())); - EXPECT_FALSE(base::IsDirectoryEmpty(empty_dir)); + EXPECT_FALSE(IsDirectoryEmpty(empty_dir)); } #if defined(OS_POSIX) @@ -1957,10 +1957,10 @@ class VerifyPathControlledByUserTest : public FileUtilTest { // |-> text_file_ base_dir_ = temp_dir_.path().AppendASCII("base_dir"); - ASSERT_TRUE(base::CreateDirectory(base_dir_)); + ASSERT_TRUE(CreateDirectory(base_dir_)); sub_dir_ = base_dir_.AppendASCII("sub_dir"); - ASSERT_TRUE(base::CreateDirectory(sub_dir_)); + ASSERT_TRUE(CreateDirectory(sub_dir_)); text_file_ = sub_dir_.AppendASCII("file.txt"); CreateTextFile(text_file_, L"This text file has some text in it."); diff --git a/base/file_util_win.cc b/base/file_util_win.cc index b9683d6..323102c 100644 --- a/base/file_util_win.cc +++ b/base/file_util_win.cc @@ -264,7 +264,7 @@ FILE* CreateAndOpenTemporaryFileInDir(const FilePath& dir, FilePath* path) { // Open file in binary mode, to avoid problems with fwrite. On Windows // it replaces \n's with \r\n's, which may surprise you. // Reference: http://msdn.microsoft.com/en-us/library/h9t88zwz(VS.71).aspx - return file_util::OpenFile(*path, "wb+"); + return OpenFile(*path, "wb+"); } bool CreateTemporaryFileInDir(const FilePath& dir, FilePath* temp_file) { @@ -530,29 +530,14 @@ bool GetFileInfo(const FilePath& file_path, PlatformFileInfo* results) { return true; } -} // namespace base - -// ----------------------------------------------------------------------------- - -namespace file_util { - -using base::DirectoryExists; -using base::FilePath; -using base::kFileShareAll; - FILE* OpenFile(const FilePath& filename, const char* mode) { - base::ThreadRestrictions::AssertIOAllowed(); + ThreadRestrictions::AssertIOAllowed(); std::wstring w_mode = ASCIIToWide(std::string(mode)); return _wfsopen(filename.value().c_str(), w_mode.c_str(), _SH_DENYNO); } -FILE* OpenFile(const std::string& filename, const char* mode) { - base::ThreadRestrictions::AssertIOAllowed(); - return _fsopen(filename.c_str(), mode, _SH_DENYNO); -} - int ReadFile(const FilePath& filename, char* data, int size) { - base::ThreadRestrictions::AssertIOAllowed(); + ThreadRestrictions::AssertIOAllowed(); base::win::ScopedHandle file(CreateFile(filename.value().c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, @@ -570,6 +555,21 @@ int ReadFile(const FilePath& filename, char* data, int size) { return -1; } +} // namespace base + +// ----------------------------------------------------------------------------- + +namespace file_util { + +using base::DirectoryExists; +using base::FilePath; +using base::kFileShareAll; + +FILE* OpenFile(const std::string& filename, const char* mode) { + base::ThreadRestrictions::AssertIOAllowed(); + return _fsopen(filename.c_str(), mode, _SH_DENYNO); +} + int WriteFile(const FilePath& filename, const char* data, int size) { base::ThreadRestrictions::AssertIOAllowed(); base::win::ScopedHandle file(CreateFile(filename.value().c_str(), diff --git a/base/files/file_util_proxy_unittest.cc b/base/files/file_util_proxy_unittest.cc index fa4a78c..17c7a3f 100644 --- a/base/files/file_util_proxy_unittest.cc +++ b/base/files/file_util_proxy_unittest.cc @@ -320,7 +320,7 @@ TEST_F(FileUtilProxyTest, WriteAndFlush) { // Verify the written data. char buffer[10]; - EXPECT_EQ(data_bytes, file_util::ReadFile(test_path(), buffer, data_bytes)); + EXPECT_EQ(data_bytes, base::ReadFile(test_path(), buffer, data_bytes)); for (int i = 0; i < data_bytes; ++i) { EXPECT_EQ(data[i], buffer[i]); } @@ -373,7 +373,7 @@ TEST_F(FileUtilProxyTest, Truncate_Shrink) { ASSERT_EQ(7, info.size); char buffer[7]; - EXPECT_EQ(7, file_util::ReadFile(test_path(), buffer, 7)); + EXPECT_EQ(7, base::ReadFile(test_path(), buffer, 7)); int i = 0; for (; i < 7; ++i) EXPECT_EQ(kTestData[i], buffer[i]); @@ -400,7 +400,7 @@ TEST_F(FileUtilProxyTest, Truncate_Expand) { ASSERT_EQ(53, info.size); char buffer[53]; - EXPECT_EQ(53, file_util::ReadFile(test_path(), buffer, 53)); + EXPECT_EQ(53, base::ReadFile(test_path(), buffer, 53)); int i = 0; for (; i < 10; ++i) EXPECT_EQ(kTestData[i], buffer[i]); diff --git a/base/memory/shared_memory_posix.cc b/base/memory/shared_memory_posix.cc index 4620247..35d8c7d 100644 --- a/base/memory/shared_memory_posix.cc +++ b/base/memory/shared_memory_posix.cc @@ -264,7 +264,7 @@ bool SharedMemory::Open(const std::string& name, bool read_only) { read_only_ = read_only; const char *mode = read_only ? "r" : "r+"; - ScopedFILE fp(file_util::OpenFile(path, mode)); + ScopedFILE fp(base::OpenFile(path, mode)); int readonly_fd_storage = -1; ScopedFD readonly_fd(&readonly_fd_storage); *readonly_fd = HANDLE_EINTR(open(path.value().c_str(), O_RDONLY)); diff --git a/base/nix/mime_util_xdg.cc b/base/nix/mime_util_xdg.cc index d695d15..dd2c7eb 100644 --- a/base/nix/mime_util_xdg.cc +++ b/base/nix/mime_util_xdg.cc @@ -255,7 +255,7 @@ FilePath IconTheme::GetIconPathUnderSubdir(const std::string& icon_name, } bool IconTheme::LoadIndexTheme(const FilePath& file) { - FILE* fp = file_util::OpenFile(file, "r"); + FILE* fp = base::OpenFile(file, "r"); SubDirInfo* current_info = NULL; if (!fp) return false; @@ -316,7 +316,7 @@ bool IconTheme::LoadIndexTheme(const FilePath& file) { } } - file_util::CloseFile(fp); + base::CloseFile(fp); return info_array_.get() != NULL; } diff --git a/base/test/gtest_xml_util.cc b/base/test/gtest_xml_util.cc index bcba363..75d023a 100644 --- a/base/test/gtest_xml_util.cc +++ b/base/test/gtest_xml_util.cc @@ -33,13 +33,13 @@ XmlUnitTestResultPrinter::~XmlUnitTestResultPrinter() { if (output_file_) { fprintf(output_file_, "</testsuites>\n"); fflush(output_file_); - file_util::CloseFile(output_file_); + base::CloseFile(output_file_); } } bool XmlUnitTestResultPrinter::Initialize(const FilePath& output_file_path) { DCHECK(!output_file_); - output_file_ = file_util::OpenFile(output_file_path, "w"); + output_file_ = OpenFile(output_file_path, "w"); if (!output_file_) return false; diff --git a/base/test/launcher/test_results_tracker.cc b/base/test/launcher/test_results_tracker.cc index b2140da..7b8dbeb 100644 --- a/base/test/launcher/test_results_tracker.cc +++ b/base/test/launcher/test_results_tracker.cc @@ -135,7 +135,7 @@ bool TestResultsTracker::Init(const CommandLine& command_line) { return false; } } - out_ = file_util::OpenFile(path, "w"); + out_ = OpenFile(path, "w"); if (!out_) { LOG(ERROR) << "Cannot open output file: " << path.value() << "."; diff --git a/base/test/perf_log.cc b/base/test/perf_log.cc index aaeb26c..efc1d42 100644 --- a/base/test/perf_log.cc +++ b/base/test/perf_log.cc @@ -18,7 +18,7 @@ bool InitPerfLog(const FilePath& log_file) { return false; } - perf_log_file = file_util::OpenFile(log_file, "w"); + perf_log_file = OpenFile(log_file, "w"); return perf_log_file != NULL; } @@ -28,7 +28,7 @@ void FinalizePerfLog() { NOTREACHED(); return; } - file_util::CloseFile(perf_log_file); + base::CloseFile(perf_log_file); } void LogPerfResult(const char* test_name, double value, const char* units) { diff --git a/base/win/shortcut_unittest.cc b/base/win/shortcut_unittest.cc index 6db5741..eaf152e 100644 --- a/base/win/shortcut_unittest.cc +++ b/base/win/shortcut_unittest.cc @@ -91,7 +91,7 @@ TEST_F(ShortcutTest, CreateAndResolveShortcut) { EXPECT_TRUE(ResolveShortcut(link_file_, &resolved_name, NULL)); char read_contents[arraysize(kFileContents)]; - file_util::ReadFile(resolved_name, read_contents, arraysize(read_contents)); + base::ReadFile(resolved_name, read_contents, arraysize(read_contents)); EXPECT_STREQ(kFileContents, read_contents); } @@ -104,7 +104,7 @@ TEST_F(ShortcutTest, ResolveShortcutWithArgs) { EXPECT_TRUE(ResolveShortcut(link_file_, &resolved_name, &args)); char read_contents[arraysize(kFileContents)]; - file_util::ReadFile(resolved_name, read_contents, arraysize(read_contents)); + base::ReadFile(resolved_name, read_contents, arraysize(read_contents)); EXPECT_STREQ(kFileContents, read_contents); EXPECT_EQ(link_properties_.arguments, args); } @@ -157,7 +157,7 @@ TEST_F(ShortcutTest, UpdateShortcutUpdateOnlyTargetAndResolve) { EXPECT_TRUE(ResolveShortcut(link_file_, &resolved_name, NULL)); char read_contents[arraysize(kFileContents2)]; - file_util::ReadFile(resolved_name, read_contents, arraysize(read_contents)); + base::ReadFile(resolved_name, read_contents, arraysize(read_contents)); EXPECT_STREQ(kFileContents2, read_contents); } |