summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorerikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-23 15:05:19 +0000
committererikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-23 15:05:19 +0000
commit2126577b81b8ff457c067e7396eea0cf6c780250 (patch)
tree1d6c812b2cff0fa9aab682d0dc534aa0ae7671c7
parent8cd1bc519a047465b0fb6018a75f1f9458c77af1 (diff)
downloadchromium_src-2126577b81b8ff457c067e7396eea0cf6c780250.zip
chromium_src-2126577b81b8ff457c067e7396eea0cf6c780250.tar.gz
chromium_src-2126577b81b8ff457c067e7396eea0cf6c780250.tar.bz2
Submitting http://codereview.chromium.org/87039 on behalf of hamaji.
Review URL: http://codereview.chromium.org/92053 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14304 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/file_util_posix.cc18
-rw-r--r--base/file_util_unittest.cc5
2 files changed, 20 insertions, 3 deletions
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
index f571c5e..073c58e 100644
--- a/base/file_util_posix.cc
+++ b/base/file_util_posix.cc
@@ -61,8 +61,9 @@ int CountFilesCreatedAfter(const FilePath& path,
DIR* dir = opendir(path.value().c_str());
if (dir) {
+ struct dirent ent_buf;
struct dirent* ent;
- while ((ent = readdir(dir)) != NULL) {
+ while (readdir_r(dir, &ent_buf, &ent) == 0 && ent) {
if ((strcmp(ent->d_name, ".") == 0) ||
(strcmp(ent->d_name, "..") == 0))
continue;
@@ -73,6 +74,21 @@ int CountFilesCreatedAfter(const FilePath& path,
LOG(ERROR) << "stat64 failed: " << strerror(errno);
continue;
}
+ // Here, we use Time::TimeT(), which discards microseconds. This
+ // means that files which are newer than |comparison_time| may
+ // be considered older. If we don't discard microseconds, it
+ // introduces another issue. Suppose the following case:
+ //
+ // 1. Get |comparison_time| by Time::Now() and the value is 10.1 (secs).
+ // 2. Create a file and the current time is 10.3 (secs).
+ //
+ // As POSIX doesn't have microsecond precision for |st_ctime|,
+ // the creation time of the file created in the step 2 is 10 and
+ // the file is considered older than |comparison_time|. After
+ // all, we may have to accept either of the two issues: 1. files
+ // which are older than |comparison_time| are considered newer
+ // (current implementation) 2. files newer than
+ // |comparison_time| are considered older.
if (st.st_ctime >= comparison_time.ToTimeT())
++file_count;
}
diff --git a/base/file_util_unittest.cc b/base/file_util_unittest.cc
index 7e0a5e5..736b0b5 100644
--- a/base/file_util_unittest.cc
+++ b/base/file_util_unittest.cc
@@ -19,6 +19,7 @@
#include "base/file_util.h"
#include "base/logging.h"
#include "base/path_service.h"
+#include "base/platform_thread.h"
#include "base/string_util.h"
#include "base/time.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -320,11 +321,11 @@ TEST_F(FileUtilTest, CountFilesCreatedAfter) {
// Age to perfection
#if defined(OS_WIN)
- Sleep(100);
+ PlatformThread::Sleep(100);
#elif defined(OS_POSIX)
// We need to wait at least one second here because the precision of
// file creation time is one second.
- sleep(1);
+ PlatformThread::Sleep(1500);
#endif
// Establish our cutoff time