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

Side by Side Diff: runtime/bin/namespace_android.cc

Issue 3001963002: [dart:io] Namespaces for file IO (Closed)
Patch Set: Fuchsia fix Created 3 years, 3 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 | « runtime/bin/namespace.cc ('k') | runtime/bin/namespace_fuchsia.cc » ('j') | 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 (c) 2017, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 #include "platform/globals.h"
6 #if defined(HOST_OS_ANDROID)
7
8 #include "bin/namespace.h"
9
10 #include <errno.h>
11 #include <fcntl.h>
12
13 #include "bin/file.h"
14 #include "bin/fdutils.h"
15 #include "platform/signal_blocker.h"
16
17 namespace dart {
18 namespace bin {
19
20 Namespace* Namespace::Create(const char* path) {
21 const int fd = TEMP_FAILURE_RETRY(open(path, O_RDONLY));
22 if (fd < 0) {
23 return NULL;
24 }
25 return new Namespace(fd);
26 }
27
28 Namespace::~Namespace() {
29 if (namespc_ != kNone) {
30 VOID_TEMP_FAILURE_RETRY(close(namespc_));
31 }
32 }
33
34 intptr_t Namespace::Default() {
35 return kNone;
36 }
37
38 const char* Namespace::GetCurrent(Namespace* namespc) {
39 if ((namespc == NULL) || (namespc->namespc() == kNone)) {
40 // TODO(zra): When there are isolate-specific namespaces, extract it from
41 // the namespace instead of calling getcwd.
42 char buffer[PATH_MAX];
43 if (getcwd(buffer, PATH_MAX) == NULL) {
44 return NULL;
45 }
46 return DartUtils::ScopedCopyCString(buffer);
47 }
48
49 // TODO(zra): Allow changing the current working directory when there is
50 // a non-default namespace.
51 return DartUtils::ScopedCopyCString("/");
52 }
53
54 bool Namespace::SetCurrent(Namespace* namespc, const char* path) {
55 if ((namespc == NULL) || (namespc->namespc() == kNone)) {
56 return (NO_RETRY_EXPECTED(chdir(path)) == 0);
57 }
58
59 // TODO(zra): If a non-default namespace is set up, changing the current
60 // working directoy is disallowed. We should relax this restriction when
61 // isolate-specific cwds are implemented.
62 errno = ENOSYS;
63 return false;
64 }
65
66 bool Namespace::ResolvePath(Namespace* namespc, const char* path,
67 intptr_t* dirfd, const char** resolved_path) {
68 ASSERT(dirfd != NULL);
69 ASSERT(resolved_path != NULL);
70 if ((namespc == NULL) || (namespc->namespc() == kNone)) {
71 *dirfd = AT_FDCWD;
72 *resolved_path = path;
73 return false;
74 }
75 *dirfd = namespc->namespc();
76 if (File::IsAbsolutePath(path)) {
77 if (strcmp(path, File::PathSeparator()) == 0) {
78 *resolved_path = ".";
79 } else {
80 *resolved_path = &path[1];
81 }
82 } else {
83 *resolved_path = path;
84 }
85 return false;
86 }
87
88 NamespaceScope::NamespaceScope(Namespace* namespc, const char* path) {
89 owns_fd_ = Namespace::ResolvePath(namespc, path, &fd_, &path_);
90 }
91
92 NamespaceScope::~NamespaceScope() {
93 if (owns_fd_) {
94 FDUtils::SaveErrorAndClose(fd_);
95 }
96 }
97
98 } // namespace bin
99 } // namespace dart
100
101 #endif // defined(HOST_OS_ANDROID)
OLDNEW
« no previous file with comments | « runtime/bin/namespace.cc ('k') | runtime/bin/namespace_fuchsia.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698