diff options
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 |