Move Touch to base namespace, remove SetLastModifiedTime.
This implements callers of SetLastModifiedTime in terms of base::Touch.
SetLastModifiedTime was just a shorthand for touch that confusingly set
both the last modified and last access times, and was only used by 7 files.
It seems better to just have the callers call Touch directly.
BUG=
R=viettrungluu@chromium.org
Review URL: https://codereview.chromium.org/100453006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238803 0039d316-1c4b-4281-b951-d872f2087c98
CrOS-Libchrome-Original-Commit: c0d50816026776361ba9d69542b880fef4df0ccf
diff --git a/base/file_util.cc b/base/file_util.cc
index 6140cea..8bcf1a4 100644
--- a/base/file_util.cc
+++ b/base/file_util.cc
@@ -173,6 +173,27 @@
return true;
}
+bool TouchFile(const FilePath& path,
+ const Time& last_accessed,
+ const Time& last_modified) {
+ int flags = PLATFORM_FILE_OPEN | PLATFORM_FILE_WRITE_ATTRIBUTES;
+
+#if defined(OS_WIN)
+ // On Windows, FILE_FLAG_BACKUP_SEMANTICS is needed to open a directory.
+ if (DirectoryExists(path))
+ flags |= PLATFORM_FILE_BACKUP_SEMANTICS;
+#endif // OS_WIN
+
+ const PlatformFile file = CreatePlatformFile(path, flags, NULL, NULL);
+ if (file != kInvalidPlatformFileValue) {
+ bool result = TouchPlatformFile(file, last_accessed, last_modified);
+ ClosePlatformFile(file);
+ return result;
+ }
+
+ return false;
+}
+
} // namespace base
// -----------------------------------------------------------------------------
@@ -183,33 +204,6 @@
using base::FilePath;
using base::kMaxUniqueFiles;
-bool TouchFile(const FilePath& path,
- const base::Time& last_accessed,
- const base::Time& last_modified) {
- int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE_ATTRIBUTES;
-
-#if defined(OS_WIN)
- // On Windows, FILE_FLAG_BACKUP_SEMANTICS is needed to open a directory.
- if (DirectoryExists(path))
- flags |= base::PLATFORM_FILE_BACKUP_SEMANTICS;
-#endif // OS_WIN
-
- const base::PlatformFile file =
- base::CreatePlatformFile(path, flags, NULL, NULL);
- if (file != base::kInvalidPlatformFileValue) {
- bool result = base::TouchPlatformFile(file, last_accessed, last_modified);
- base::ClosePlatformFile(file);
- return result;
- }
-
- return false;
-}
-
-bool SetLastModifiedTime(const FilePath& path,
- const base::Time& last_modified) {
- return TouchFile(path, last_modified, last_modified);
-}
-
bool CloseFile(FILE* file) {
if (file == NULL)
return true;
diff --git a/base/file_util.h b/base/file_util.h
index 5282888..1fea6e8 100644
--- a/base/file_util.h
+++ b/base/file_util.h
@@ -294,21 +294,17 @@
// Returns information about the given file path.
BASE_EXPORT bool GetFileInfo(const FilePath& file_path, PlatformFileInfo* info);
+// Sets the time of the last access and the time of the last modification.
+BASE_EXPORT bool TouchFile(const FilePath& path,
+ const Time& last_accessed,
+ const Time& last_modified);
+
} // namespace base
// -----------------------------------------------------------------------------
namespace file_util {
-// Sets the time of the last access and the time of the last modification.
-BASE_EXPORT bool TouchFile(const base::FilePath& path,
- const base::Time& last_accessed,
- const base::Time& last_modified);
-
-// Set the time of the last modification. Useful for unit tests.
-BASE_EXPORT bool SetLastModifiedTime(const base::FilePath& path,
- const base::Time& last_modified);
-
#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);
diff --git a/base/file_util_unittest.cc b/base/file_util_unittest.cc
index 38bfbc0..4ffa4ba 100644
--- a/base/file_util_unittest.cc
+++ b/base/file_util_unittest.cc
@@ -1893,7 +1893,7 @@
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");
@@ -1911,7 +1911,7 @@
ASSERT_TRUE(Time::FromString("Tue, 15 Nov 1994, 12:45:26 GMT",
&modification_time));
- ASSERT_TRUE(file_util::TouchFile(foobar, access_time, modification_time));
+ ASSERT_TRUE(TouchFile(foobar, access_time, modification_time));
PlatformFileInfo file_info;
ASSERT_TRUE(GetFileInfo(foobar, &file_info));
EXPECT_EQ(file_info.last_accessed.ToInternalValue(),
diff --git a/base/files/file_util_proxy.cc b/base/files/file_util_proxy.cc
index eefb7a1..40cac11 100644
--- a/base/files/file_util_proxy.cc
+++ b/base/files/file_util_proxy.cc
@@ -357,8 +357,7 @@
return base::PostTaskAndReplyWithResult(
task_runner,
FROM_HERE,
- Bind(&file_util::TouchFile, file_path,
- last_access_time, last_modified_time),
+ Bind(&TouchFile, file_path, last_access_time, last_modified_time),
Bind(&CallWithTranslatedParameter, callback));
}