diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-21 01:50:39 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-21 01:50:39 +0000 |
commit | 4b7743de2632a9d226bd5494b90eee6baceb5855 (patch) | |
tree | a5101566eecf3e1b66845bd62393f97e4bf509f0 /base/file_util_posix.cc | |
parent | a0b1c513361089833a7b2ecdc5483eff0d944d60 (diff) | |
download | chromium_src-4b7743de2632a9d226bd5494b90eee6baceb5855.zip chromium_src-4b7743de2632a9d226bd5494b90eee6baceb5855.tar.gz chromium_src-4b7743de2632a9d226bd5494b90eee6baceb5855.tar.bz2 |
Implement file_util::CountFilesCreatedAfter() for posix environments.
BUG=9833
Review URL: http://codereview.chromium.org/87003
Patch from Shinichiro Hamaji <hamaji@google.com>.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14081 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util_posix.cc')
-rw-r--r-- | base/file_util_posix.cc | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc index ad3fc581..6a36c62 100644 --- a/base/file_util_posix.cc +++ b/base/file_util_posix.cc @@ -4,6 +4,7 @@ #include "base/file_util.h" +#include <dirent.h> #include <errno.h> #include <fcntl.h> #include <fnmatch.h> @@ -14,7 +15,9 @@ #include <sys/errno.h> #include <sys/mman.h> #include <sys/stat.h> +#include <sys/types.h> #include <time.h> +#include <unistd.h> #include <fstream> @@ -22,6 +25,7 @@ #include "base/file_path.h" #include "base/logging.h" #include "base/string_util.h" +#include "base/time.h" namespace file_util { @@ -51,6 +55,32 @@ bool AbsolutePath(FilePath* path) { return true; } +int CountFilesCreatedAfter(const FilePath& path, + const base::Time& comparison_time) { + int file_count = 0; + + DIR* dir = opendir(path.value().c_str()); + if (dir) { + struct dirent* ent; + while ((ent = readdir(dir)) != NULL) { + if ((strcmp(ent->d_name, ".") == 0) || + (strcmp(ent->d_name, "..") == 0)) + continue; + + struct stat64 st; + int test = stat64(path.Append(ent->d_name).value().c_str(), &st); + if (test != 0) { + LOG(ERROR) << "stat64 failed: " << strerror(errno); + continue; + } + if (st.st_ctime >= comparison_time.ToTimeT()) + ++file_count; + } + closedir(dir); + } + return file_count; +} + // TODO(erikkay): The Windows version of this accepts paths like "foo/bar/*" // which works both with and without the recursive flag. I'm not sure we need // that functionality. If not, remove from file_util_win.cc, otherwise add it |