diff options
author | erikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-23 15:05:19 +0000 |
---|---|---|
committer | erikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-23 15:05:19 +0000 |
commit | 2126577b81b8ff457c067e7396eea0cf6c780250 (patch) | |
tree | 1d6c812b2cff0fa9aab682d0dc534aa0ae7671c7 /base/file_util_posix.cc | |
parent | 8cd1bc519a047465b0fb6018a75f1f9458c77af1 (diff) | |
download | chromium_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
Diffstat (limited to 'base/file_util_posix.cc')
-rw-r--r-- | base/file_util_posix.cc | 18 |
1 files changed, 17 insertions, 1 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; } |