Chromium Code Reviews| Index: runtime/bin/file_macos.cc |
| diff --git a/runtime/bin/file_macos.cc b/runtime/bin/file_macos.cc |
| index 767908ec6066cbec29160ca1b459cd55f8ae3f34..842982f1dd98fa72909298613818b01c6f850037 100644 |
| --- a/runtime/bin/file_macos.cc |
| +++ b/runtime/bin/file_macos.cc |
| @@ -15,6 +15,7 @@ |
| #include <sys/mman.h> // NOLINT |
| #include <sys/stat.h> // NOLINT |
| #include <unistd.h> // NOLINT |
| +#include <utime.h> // NOLINT |
| #include "bin/builtin.h" |
| #include "bin/fdutils.h" |
| @@ -344,18 +345,26 @@ bool File::Copy(const char* old_path, const char* new_path) { |
| } |
| +static bool StatHelper(const char* name, struct stat* st) { |
| + if (NO_RETRY_EXPECTED(stat(name, st)) != 0) { |
| + return false; |
| + } |
| + // Signal an error if it's a directory. |
| + if (S_ISDIR(st->st_mode)) { |
| + errno = EISDIR; |
| + return false; |
| + } |
| + // Otherwise assume the caller knows what it's doing. |
| + return true; |
| +} |
| + |
| + |
| int64_t File::LengthFromPath(const char* name) { |
| struct stat st; |
| - if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) { |
| - // Signal an error if it's a directory. |
| - if (S_ISDIR(st.st_mode)) { |
| - errno = EISDIR; |
| - return -1; |
| - } |
| - // Otherwise assume the caller knows what it's doing. |
| - return st.st_size; |
| + if (!StatHelper(name, &st)) { |
| + return -1; |
| } |
| - return -1; |
| + return st.st_size; |
| } |
| @@ -393,16 +402,49 @@ void File::Stat(const char* name, int64_t* data) { |
| time_t File::LastModified(const char* name) { |
| struct stat st; |
| - if (NO_RETRY_EXPECTED(stat(name, &st)) == 0) { |
| - // Signal an error if it's a directory. |
| - if (S_ISDIR(st.st_mode)) { |
| - errno = EISDIR; |
| - return -1; |
| - } |
| - // Otherwise assume the caller knows what it's doing. |
| - return st.st_mtime; |
| + if (!StatHelper(name, &st)) { |
| + return -1; |
| } |
| - return -1; |
| + return st.st_mtime; |
| +} |
| + |
| + |
| +time_t File::LastAccessed(const char* name) { |
| + struct stat st; |
| + if (!StatHelper(name, &st)) { |
| + return -1; |
| + } |
| + return st.st_atime; |
| +} |
| + |
| + |
| +bool File::SetLastAccessed(const char* name, int64_t millis) { |
| + // First get the current times. |
| + struct stat st; |
| + if (!StatHelper(name, &st)) { |
| + return false; |
| + } |
| + |
| + // Set the new time: |
| + struct utimbuf times; |
| + times.actime = millis / kMillisecondsPerSecond; |
| + times.modtime = st.st_mtime; |
| + return utime(name, ×) == 0; |
| +} |
| + |
| + |
| +bool File::SetLastModified(const char* name, int64_t millis) { |
| + // First get the current times. |
| + struct stat st; |
| + if (!StatHelper(name, &st)) { |
| + return false; |
| + } |
| + |
| + // Set the new time: |
| + struct utimbuf times; |
| + times.actime = st.st_atime; |
|
siva
2017/02/08 21:18:29
ditto comment about access time here.
zra
2017/02/09 17:21:38
Acknowledged.
|
| + times.modtime = millis / kMillisecondsPerSecond; |
| + return utime(name, ×) == 0; |
| } |