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

Unified Diff: runtime/bin/file_win.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_patch.dart ('k') | runtime/bin/io_natives.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/file_win.cc
diff --git a/runtime/bin/file_win.cc b/runtime/bin/file_win.cc
index 3cfdf69b2158b368b5b2a6026236e91f65ebad7c..9101ee6673b74fc53b2b0336ccbfa73fb49b1105 100644
--- a/runtime/bin/file_win.cc
+++ b/runtime/bin/file_win.cc
@@ -12,6 +12,7 @@
#include <stdio.h> // NOLINT
#include <string.h> // NOLINT
#include <sys/stat.h> // NOLINT
+#include <sys/utime.h> // NOLINT
#include <WinIoCtl.h> // NOLINT
#include "bin/builtin.h"
@@ -255,15 +256,23 @@ File* File::OpenStdio(int fd) {
}
+static bool StatHelper(wchar_t* path, struct __stat64* st) {
+ int stat_status = _wstat64(path, st);
+ if (stat_status != 0) {
+ return false;
+ }
+ if ((st->st_mode & S_IFMT) != S_IFREG) {
+ SetLastError(ERROR_NOT_SUPPORTED);
+ return false;
+ }
+ return true;
+}
+
+
bool File::Exists(const char* name) {
struct __stat64 st;
Utf8ToWideScope system_name(name);
- bool stat_status = _wstat64(system_name.wide(), &st);
- if (stat_status == 0) {
- return ((st.st_mode & S_IFMT) == S_IFREG);
- } else {
- return false;
- }
+ return StatHelper(system_name.wide(), &st);
}
@@ -442,16 +451,10 @@ bool File::Copy(const char* old_path, const char* new_path) {
int64_t File::LengthFromPath(const char* name) {
struct __stat64 st;
Utf8ToWideScope system_name(name);
- int stat_status = _wstat64(system_name.wide(), &st);
- if (stat_status == 0) {
- if ((st.st_mode & S_IFMT) == S_IFREG) {
- return st.st_size;
- } else {
- // ERROR_DIRECTORY_NOT_SUPPORTED is not always in the message table.
- SetLastError(ERROR_NOT_SUPPORTED);
- }
+ if (!StatHelper(system_name.wide(), &st)) {
+ return -1;
}
- return -1;
+ return st.st_size;
}
@@ -539,19 +542,55 @@ void File::Stat(const char* name, int64_t* data) {
}
+time_t File::LastAccessed(const char* name) {
+ struct __stat64 st;
+ Utf8ToWideScope system_name(name);
+ if (!StatHelper(system_name.wide(), &st)) {
+ return -1;
+ }
+ return st.st_atime;
+}
+
+
time_t File::LastModified(const char* name) {
struct __stat64 st;
Utf8ToWideScope system_name(name);
- int stat_status = _wstat64(system_name.wide(), &st);
- if (stat_status == 0) {
- if ((st.st_mode & S_IFMT) == S_IFREG) {
- return st.st_mtime;
- } else {
- // ERROR_DIRECTORY_NOT_SUPPORTED is not always in the message table.
- SetLastError(ERROR_NOT_SUPPORTED);
- }
+ if (!StatHelper(system_name.wide(), &st)) {
+ return -1;
}
- return -1;
+ return st.st_mtime;
+}
+
+
+bool File::SetLastAccessed(const char* name, int64_t millis) {
+ // First get the current times.
+ struct __stat64 st;
+ Utf8ToWideScope system_name(name);
+ if (!StatHelper(system_name.wide(), &st)) {
+ return false;
+ }
+
+ // Set the new time:
+ struct __utimbuf64 times;
+ times.actime = millis / kMillisecondsPerSecond;
+ times.modtime = st.st_mtime;
+ return _wutime64(system_name.wide(), &times) == 0;
+}
+
+
+bool File::SetLastModified(const char* name, int64_t millis) {
+ // First get the current times.
+ struct __stat64 st;
+ Utf8ToWideScope system_name(name);
+ if (!StatHelper(system_name.wide(), &st)) {
+ return false;
+ }
+
+ // Set the new time:
+ struct __utimbuf64 times;
+ times.actime = st.st_atime;
+ times.modtime = millis / kMillisecondsPerSecond;
+ return _wutime64(system_name.wide(), &times) == 0;
}
« no previous file with comments | « runtime/bin/file_patch.dart ('k') | runtime/bin/io_natives.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698