Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3108)

Unified Diff: base/file_util_posix.cc

Issue 87039: Fixes for comments on the review 87003.... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/file_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/file_util_posix.cc
===================================================================
--- base/file_util_posix.cc (revision 14268)
+++ base/file_util_posix.cc (working copy)
@@ -61,8 +61,9 @@
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 @@
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;
}
« no previous file with comments | « no previous file | base/file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698