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

Unified Diff: services/files/shared_impl.cc

Issue 963093004: Files: Add basic implementation of Directory and some basic tests. (Closed) Base URL: https://github.com/domokit/mojo.git@file_man
Patch Set: oops Created 5 years, 9 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 | « services/files/shared_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/files/shared_impl.cc
diff --git a/services/files/shared_impl.cc b/services/files/shared_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a9ac95d08c7a8115ae661652fc2c8659053bd622
--- /dev/null
+++ b/services/files/shared_impl.cc
@@ -0,0 +1,80 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "services/files/shared_impl.h"
+
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <time.h>
+#include <unistd.h>
+
+#include "base/logging.h"
+#include "services/files/futimens.h"
+#include "services/files/util.h"
+
+namespace mojo {
+namespace files {
+
+void StatFD(int fd, const Callback<void(Error, FileInformationPtr)>& callback) {
+ DCHECK_NE(fd, -1);
+
+ struct stat buf;
+ if (fstat(fd, &buf) != 0) {
+ callback.Run(ErrnoToError(errno), nullptr);
+ return;
+ }
+
+ FileInformationPtr file_info(FileInformation::New());
+ // Only fill in |size| for files.
+ if (S_ISREG(buf.st_mode)) {
+ file_info->size = static_cast<int64_t>(buf.st_size);
+ } else {
+ LOG_IF(WARNING, !S_ISDIR(buf.st_mode))
+ << "Unexpected fstat() of special file";
+ file_info->size = 0;
+ }
+ file_info->atime = Timespec::New();
+ file_info->mtime = Timespec::New();
+#if defined(OS_ANDROID)
+ file_info->atime->seconds = static_cast<int64_t>(buf.st_atime);
+ file_info->atime->nanoseconds = static_cast<int32_t>(buf.st_atime_nsec);
+ file_info->mtime->seconds = static_cast<int64_t>(buf.st_mtime);
+ file_info->mtime->nanoseconds = static_cast<int32_t>(buf.st_mtime_nsec);
+#else
+ file_info->atime->seconds = static_cast<int64_t>(buf.st_atim.tv_sec);
+ file_info->atime->nanoseconds = static_cast<int32_t>(buf.st_atim.tv_nsec);
+ file_info->mtime->seconds = static_cast<int64_t>(buf.st_mtim.tv_sec);
+ file_info->mtime->nanoseconds = static_cast<int32_t>(buf.st_mtim.tv_nsec);
+#endif
+
+ callback.Run(ERROR_OK, file_info.Pass());
+}
+
+void TouchFD(int fd,
+ TimespecOrNowPtr atime,
+ TimespecOrNowPtr mtime,
+ const Callback<void(Error)>& callback) {
+ DCHECK_NE(fd, -1);
+
+ struct timespec times[2];
+ if (Error error = TimespecOrNowToStandardTimespec(atime.get(), &times[0])) {
+ callback.Run(error);
+ return;
+ }
+ if (Error error = TimespecOrNowToStandardTimespec(mtime.get(), &times[1])) {
+ callback.Run(error);
+ return;
+ }
+
+ if (futimens(fd, times) != 0) {
+ callback.Run(ErrnoToError(errno));
+ return;
+ }
+
+ callback.Run(ERROR_OK);
+}
+
+} // namespace files
+} // namespace mojo
« no previous file with comments | « services/files/shared_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698