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

Unified Diff: runtime/bin/file_fuchsia.cc

Issue 2681683005: [dart:io] Adds functions to set file access and modification time (Closed)
Patch Set: Update changelog Created 3 years, 10 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 | « runtime/bin/file_android.cc ('k') | runtime/bin/file_linux.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/file_fuchsia.cc
diff --git a/runtime/bin/file_fuchsia.cc b/runtime/bin/file_fuchsia.cc
index 7175d55c8f79578a36e62d813c06f0d0cdae513f..19595953a8cc17f30127a20f710987753ca0b54f 100644
--- a/runtime/bin/file_fuchsia.cc
+++ b/runtime/bin/file_fuchsia.cc
@@ -14,6 +14,7 @@
#include <sys/stat.h> // NOLINT
#include <sys/types.h> // NOLINT
#include <unistd.h> // NOLINT
+#include <utime.h> // NOLINT
#include "bin/builtin.h"
#include "bin/fdutils.h"
@@ -359,18 +360,26 @@ bool File::Copy(const char* old_path, const char* new_path) {
}
+static bool StatHelper(const char* name, struct stat64* st) {
+ if (NO_RETRY_EXPECTED(stat64(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;
+ struct stat64 st;
+ if (!StatHelper(name, &st)) {
+ return -1;
}
- return -1;
+ return st.st_size;
}
@@ -399,16 +408,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, &times) == 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;
+ times.modtime = millis / kMillisecondsPerSecond;
+ return utime(name, &times) == 0;
}
« no previous file with comments | « runtime/bin/file_android.cc ('k') | runtime/bin/file_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698