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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « services/files/shared_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "services/files/shared_impl.h"
6
7 #include <errno.h>
8 #include <sys/stat.h>
9 #include <sys/types.h>
10 #include <time.h>
11 #include <unistd.h>
12
13 #include "base/logging.h"
14 #include "services/files/futimens.h"
15 #include "services/files/util.h"
16
17 namespace mojo {
18 namespace files {
19
20 void StatFD(int fd, const Callback<void(Error, FileInformationPtr)>& callback) {
21 DCHECK_NE(fd, -1);
22
23 struct stat buf;
24 if (fstat(fd, &buf) != 0) {
25 callback.Run(ErrnoToError(errno), nullptr);
26 return;
27 }
28
29 FileInformationPtr file_info(FileInformation::New());
30 // Only fill in |size| for files.
31 if (S_ISREG(buf.st_mode)) {
32 file_info->size = static_cast<int64_t>(buf.st_size);
33 } else {
34 LOG_IF(WARNING, !S_ISDIR(buf.st_mode))
35 << "Unexpected fstat() of special file";
36 file_info->size = 0;
37 }
38 file_info->atime = Timespec::New();
39 file_info->mtime = Timespec::New();
40 #if defined(OS_ANDROID)
41 file_info->atime->seconds = static_cast<int64_t>(buf.st_atime);
42 file_info->atime->nanoseconds = static_cast<int32_t>(buf.st_atime_nsec);
43 file_info->mtime->seconds = static_cast<int64_t>(buf.st_mtime);
44 file_info->mtime->nanoseconds = static_cast<int32_t>(buf.st_mtime_nsec);
45 #else
46 file_info->atime->seconds = static_cast<int64_t>(buf.st_atim.tv_sec);
47 file_info->atime->nanoseconds = static_cast<int32_t>(buf.st_atim.tv_nsec);
48 file_info->mtime->seconds = static_cast<int64_t>(buf.st_mtim.tv_sec);
49 file_info->mtime->nanoseconds = static_cast<int32_t>(buf.st_mtim.tv_nsec);
50 #endif
51
52 callback.Run(ERROR_OK, file_info.Pass());
53 }
54
55 void TouchFD(int fd,
56 TimespecOrNowPtr atime,
57 TimespecOrNowPtr mtime,
58 const Callback<void(Error)>& callback) {
59 DCHECK_NE(fd, -1);
60
61 struct timespec times[2];
62 if (Error error = TimespecOrNowToStandardTimespec(atime.get(), &times[0])) {
63 callback.Run(error);
64 return;
65 }
66 if (Error error = TimespecOrNowToStandardTimespec(mtime.get(), &times[1])) {
67 callback.Run(error);
68 return;
69 }
70
71 if (futimens(fd, times) != 0) {
72 callback.Run(ErrnoToError(errno));
73 return;
74 }
75
76 callback.Run(ERROR_OK);
77 }
78
79 } // namespace files
80 } // namespace mojo
OLDNEW
« 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