summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/file_util.cc40
-rw-r--r--base/file_util.h14
-rw-r--r--base/file_util_unittest.cc4
-rw-r--r--base/files/file_util_proxy.cc3
-rw-r--r--chrome/browser/browsing_data/browsing_data_remover_unittest.cc20
-rw-r--r--chrome/browser/chromeos/file_manager/file_manager_browsertest.cc3
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_database_unittest.cc6
-rw-r--r--content/browser/storage_partition_impl_unittest.cc16
-rw-r--r--net/disk_cache/simple/simple_index_file_unittest.cc6
-rw-r--r--net/proxy/proxy_config_service_linux_unittest.cc2
-rw-r--r--webkit/browser/blob/local_file_stream_reader_unittest.cc6
-rw-r--r--webkit/browser/database/database_tracker_unittest.cc16
-rw-r--r--webkit/browser/fileapi/native_file_util.cc5
13 files changed, 69 insertions, 72 deletions
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,42 +173,36 @@ bool GetFileSize(const FilePath& file_path, int64* file_size) {
return true;
}
-} // namespace base
-
-// -----------------------------------------------------------------------------
-
-namespace file_util {
-
-using base::FileEnumerator;
-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;
+ 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 |= base::PLATFORM_FILE_BACKUP_SEMANTICS;
+ flags |= 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);
+ 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;
}
-bool SetLastModifiedTime(const FilePath& path,
- const base::Time& last_modified) {
- return TouchFile(path, last_modified, last_modified);
-}
+} // namespace base
+
+// -----------------------------------------------------------------------------
+
+namespace file_util {
+
+using base::FileEnumerator;
+using base::FilePath;
+using base::kMaxUniqueFiles;
bool CloseFile(FILE* file) {
if (file == NULL)
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 @@ BASE_EXPORT bool IsLink(const FilePath& file_path);
// 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 @@ TEST_F(FileUtilTest, TouchFile) {
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 @@ TEST_F(FileUtilTest, TouchFile) {
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 @@ bool FileUtilProxy::Touch(
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));
}
diff --git a/chrome/browser/browsing_data/browsing_data_remover_unittest.cc b/chrome/browser/browsing_data/browsing_data_remover_unittest.cc
index 848c271..99c3f73 100644
--- a/chrome/browser/browsing_data/browsing_data_remover_unittest.cc
+++ b/chrome/browser/browsing_data/browsing_data_remover_unittest.cc
@@ -563,14 +563,18 @@ class RemoveLocalStorageTester {
file_util::WriteFile(storage_path.Append(kDomStorageExt), NULL, 0);
// Tweak their dates.
- file_util::SetLastModifiedTime(storage_path.Append(kDomStorageOrigin1),
- base::Time::Now());
- file_util::SetLastModifiedTime(storage_path.Append(kDomStorageOrigin2),
- base::Time::Now() - base::TimeDelta::FromDays(1));
- file_util::SetLastModifiedTime(storage_path.Append(kDomStorageOrigin3),
- base::Time::Now() - base::TimeDelta::FromDays(60));
- file_util::SetLastModifiedTime(storage_path.Append(kDomStorageExt),
- base::Time::Now());
+ base::Time now = base::Time::Now();
+ base::TouchFile(storage_path.Append(kDomStorageOrigin1), now, now);
+
+ base::Time one_day_ago = now - base::TimeDelta::FromDays(1);
+ base::TouchFile(storage_path.Append(kDomStorageOrigin2),
+ one_day_ago, one_day_ago);
+
+ base::Time sixty_days_ago = now - base::TimeDelta::FromDays(60);
+ base::TouchFile(storage_path.Append(kDomStorageOrigin3),
+ sixty_days_ago, sixty_days_ago);
+
+ base::TouchFile(storage_path.Append(kDomStorageExt), now, now);
}
private:
diff --git a/chrome/browser/chromeos/file_manager/file_manager_browsertest.cc b/chrome/browser/chromeos/file_manager/file_manager_browsertest.cc
index f9ccdbf..4ea8167 100644
--- a/chrome/browser/chromeos/file_manager/file_manager_browsertest.cc
+++ b/chrome/browser/chromeos/file_manager/file_manager_browsertest.cc
@@ -236,7 +236,8 @@ class LocalTestVolume {
// TestEntryInfo. Returns true on success.
bool UpdateModifiedTime(const TestEntryInfo& entry) {
const base::FilePath path = local_path_.AppendASCII(entry.target_path);
- if (!file_util::SetLastModifiedTime(path, entry.last_modified_time))
+ if (!base::TouchFile(path, entry.last_modified_time,
+ entry.last_modified_time))
return false;
// Update the modified time of parent directories because it may be also
diff --git a/chrome/browser/safe_browsing/safe_browsing_database_unittest.cc b/chrome/browser/safe_browsing/safe_browsing_database_unittest.cc
index 8d3f21f..9810858 100644
--- a/chrome/browser/safe_browsing/safe_browsing_database_unittest.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_database_unittest.cc
@@ -1643,7 +1643,7 @@ TEST_F(SafeBrowsingDatabaseTest, EmptyUpdate) {
// Inserting another chunk updates the database file. The sleep is
// needed because otherwise the entire test can finish w/in the
// resolution of the lastmod time.
- ASSERT_TRUE(file_util::SetLastModifiedTime(filename, old_last_modified));
+ ASSERT_TRUE(base::TouchFile(filename, old_last_modified, old_last_modified));
ASSERT_TRUE(base::GetFileInfo(filename, &before_info));
EXPECT_TRUE(database_->UpdateStarted(&lists));
chunk.hosts.clear();
@@ -1657,7 +1657,7 @@ TEST_F(SafeBrowsingDatabaseTest, EmptyUpdate) {
EXPECT_LT(before_info.last_modified, after_info.last_modified);
// Deleting a chunk updates the database file.
- ASSERT_TRUE(file_util::SetLastModifiedTime(filename, old_last_modified));
+ ASSERT_TRUE(base::TouchFile(filename, old_last_modified, old_last_modified));
ASSERT_TRUE(base::GetFileInfo(filename, &before_info));
EXPECT_TRUE(database_->UpdateStarted(&lists));
AddDelChunk(safe_browsing_util::kMalwareList, chunk.chunk_number);
@@ -1667,7 +1667,7 @@ TEST_F(SafeBrowsingDatabaseTest, EmptyUpdate) {
// Simply calling |UpdateStarted()| then |UpdateFinished()| does not
// update the database file.
- ASSERT_TRUE(file_util::SetLastModifiedTime(filename, old_last_modified));
+ ASSERT_TRUE(base::TouchFile(filename, old_last_modified, old_last_modified));
ASSERT_TRUE(base::GetFileInfo(filename, &before_info));
EXPECT_TRUE(database_->UpdateStarted(&lists));
database_->UpdateFinished(true);
diff --git a/content/browser/storage_partition_impl_unittest.cc b/content/browser/storage_partition_impl_unittest.cc
index 008a898..ef3b679 100644
--- a/content/browser/storage_partition_impl_unittest.cc
+++ b/content/browser/storage_partition_impl_unittest.cc
@@ -210,12 +210,16 @@ class RemoveLocalStorageTester {
file_util::WriteFile(storage_path.Append(kDomStorageOrigin3), NULL, 0);
// Tweak their dates.
- file_util::SetLastModifiedTime(storage_path.Append(kDomStorageOrigin1),
- base::Time::Now());
- file_util::SetLastModifiedTime(storage_path.Append(kDomStorageOrigin2),
- base::Time::Now() - base::TimeDelta::FromDays(1));
- file_util::SetLastModifiedTime(storage_path.Append(kDomStorageOrigin3),
- base::Time::Now() - base::TimeDelta::FromDays(60));
+ base::Time now = base::Time::Now();
+ base::TouchFile(storage_path.Append(kDomStorageOrigin1), now, now);
+
+ base::Time one_day_ago = now - base::TimeDelta::FromDays(1);
+ base::TouchFile(storage_path.Append(kDomStorageOrigin2),
+ one_day_ago, one_day_ago);
+
+ base::Time sixty_days_ago = now - base::TimeDelta::FromDays(60);
+ base::TouchFile(storage_path.Append(kDomStorageOrigin3),
+ sixty_days_ago, sixty_days_ago);
}
private:
diff --git a/net/disk_cache/simple/simple_index_file_unittest.cc b/net/disk_cache/simple/simple_index_file_unittest.cc
index ef7c26d..17aa595 100644
--- a/net/disk_cache/simple/simple_index_file_unittest.cc
+++ b/net/disk_cache/simple/simple_index_file_unittest.cc
@@ -178,13 +178,13 @@ TEST_F(SimpleIndexFileTest, LegacyIsIndexFileStale) {
const base::Time past_time = base::Time::Now() -
base::TimeDelta::FromSeconds(10);
- EXPECT_TRUE(file_util::TouchFile(index_path, past_time, past_time));
- EXPECT_TRUE(file_util::TouchFile(cache_path, past_time, past_time));
+ EXPECT_TRUE(base::TouchFile(index_path, past_time, past_time));
+ EXPECT_TRUE(base::TouchFile(cache_path, past_time, past_time));
ASSERT_TRUE(simple_util::GetMTime(cache_path, &cache_mtime));
EXPECT_FALSE(
WrappedSimpleIndexFile::LegacyIsIndexFileStale(cache_mtime, index_path));
const base::Time even_older = past_time - base::TimeDelta::FromSeconds(10);
- EXPECT_TRUE(file_util::TouchFile(index_path, even_older, even_older));
+ EXPECT_TRUE(base::TouchFile(index_path, even_older, even_older));
EXPECT_TRUE(
WrappedSimpleIndexFile::LegacyIsIndexFileStale(cache_mtime, index_path));
}
diff --git a/net/proxy/proxy_config_service_linux_unittest.cc b/net/proxy/proxy_config_service_linux_unittest.cc
index c3a1aa5..99a3b570b 100644
--- a/net/proxy/proxy_config_service_linux_unittest.cc
+++ b/net/proxy/proxy_config_service_linux_unittest.cc
@@ -1597,7 +1597,7 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEHomePicker) {
// Finally, make the .kde4 config directory older than the .kde directory
// and make sure we then use .kde instead of .kde4 since it's newer.
- file_util::SetLastModifiedTime(kde4_config_, base::Time());
+ base::TouchFile(kde4_config_, base::Time(), base::Time());
{ SCOPED_TRACE("KDE4, very old .kde4 directory present, use .kde");
MockEnvironment* env = new MockEnvironment;
diff --git a/webkit/browser/blob/local_file_stream_reader_unittest.cc b/webkit/browser/blob/local_file_stream_reader_unittest.cc
index ef7fb60..87c77fc 100644
--- a/webkit/browser/blob/local_file_stream_reader_unittest.cc
+++ b/webkit/browser/blob/local_file_stream_reader_unittest.cc
@@ -94,9 +94,9 @@ class LocalFileStreamReaderTest : public testing::Test {
void TouchTestFile() {
base::Time new_modified_time =
test_file_modification_time() - base::TimeDelta::FromSeconds(1);
- ASSERT_TRUE(file_util::TouchFile(test_path(),
- test_file_modification_time(),
- new_modified_time));
+ ASSERT_TRUE(base::TouchFile(test_path(),
+ test_file_modification_time(),
+ new_modified_time));
}
base::MessageLoopProxy* file_task_runner() const {
diff --git a/webkit/browser/database/database_tracker_unittest.cc b/webkit/browser/database/database_tracker_unittest.cc
index 8c3bc0d..bb931d4 100644
--- a/webkit/browser/database/database_tracker_unittest.cc
+++ b/webkit/browser/database/database_tracker_unittest.cc
@@ -273,14 +273,14 @@ class DatabaseTracker_TestHelper_Test {
// Setup file modification times. db1 and db2 are modified now, db3 three
// days ago.
- EXPECT_TRUE(file_util::SetLastModifiedTime(
- tracker->GetFullDBFilePath(kOrigin1, kDB1), base::Time::Now()));
- EXPECT_TRUE(file_util::SetLastModifiedTime(
- tracker->GetFullDBFilePath(kOrigin2, kDB2), base::Time::Now()));
- base::Time three_days_ago = base::Time::Now();
- three_days_ago -= base::TimeDelta::FromDays(3);
- EXPECT_TRUE(file_util::SetLastModifiedTime(
- tracker->GetFullDBFilePath(kOrigin2, kDB3), three_days_ago));
+ base::Time now = base::Time::Now();
+ EXPECT_TRUE(base::TouchFile(tracker->GetFullDBFilePath(kOrigin1, kDB1),
+ now, now));
+ EXPECT_TRUE(base::TouchFile(tracker->GetFullDBFilePath(kOrigin2, kDB2),
+ now, now));
+ base::Time three_days_ago = now - base::TimeDelta::FromDays(3);
+ EXPECT_TRUE(base::TouchFile(tracker->GetFullDBFilePath(kOrigin2, kDB3),
+ three_days_ago, three_days_ago));
// Delete databases modified since yesterday. db2 is whitelisted.
base::Time yesterday = base::Time::Now();
diff --git a/webkit/browser/fileapi/native_file_util.cc b/webkit/browser/fileapi/native_file_util.cc
index d195d1e..549de91 100644
--- a/webkit/browser/fileapi/native_file_util.cc
+++ b/webkit/browser/fileapi/native_file_util.cc
@@ -173,8 +173,7 @@ PlatformFileError NativeFileUtil::Touch(
const base::FilePath& path,
const base::Time& last_access_time,
const base::Time& last_modified_time) {
- if (!file_util::TouchFile(
- path, last_access_time, last_modified_time))
+ if (!base::TouchFile(path, last_access_time, last_modified_time))
return base::PLATFORM_FILE_ERROR_FAILED;
return base::PLATFORM_FILE_OK;
}
@@ -244,7 +243,7 @@ PlatformFileError NativeFileUtil::CopyOrMoveFile(
// Preserve the last modified time. Do not return error here even if
// the setting is failed, because the copy itself is successfully done.
if (option == FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED)
- file_util::SetLastModifiedTime(dest_path, last_modified);
+ base::TouchFile(dest_path, last_modified, last_modified);
return base::PLATFORM_FILE_OK;
}