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

Side by Side Diff: runtime/bin/namespace_fuchsia.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_android.cc ('k') | runtime/bin/namespace_linux.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_FUCHSIA)
7
8 #include "bin/namespace.h"
9
10 #include <errno.h>
11 #include <fcntl.h>
12 #include <mxio/namespace.h>
13
14 #include "bin/file.h"
15 #include "bin/fdutils.h"
16 #include "platform/signal_blocker.h"
17
18 namespace dart {
19 namespace bin {
20
21 Namespace* Namespace::Create(const char* path) {
22 UNIMPLEMENTED();
23 return NULL;
24 }
25
26 Namespace::~Namespace() {
27 if (namespc_ != kNone) {
28 mxio_ns_t* ns = reinterpret_cast<mxio_ns_t*>(namespc_);
29 mx_status_t status = mxio_ns_destroy(ns);
30 ASSERT(status == MX_OK);
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 // TODO(zra): Allow changing the current working directory when there is
49 // a non-default namespace.
50 return DartUtils::ScopedCopyCString("/");
51 }
52
53 bool Namespace::SetCurrent(Namespace* namespc, const char* path) {
54 if ((namespc == NULL) || (namespc->namespc() == kNone)) {
55 return (NO_RETRY_EXPECTED(chdir(path)) == 0);
56 }
57 // TODO(zra): If a non-default namespace is set up, changing the current
58 // working directoy is disallowed. We should relax this restriction when
59 // isolate-specific cwds are implemented.
60 errno = ENOSYS;
61 return false;
62 }
63
64 bool Namespace::ResolvePath(Namespace* namespc, const char* path,
65 intptr_t* dirfd, const char** resolved_path) {
66 ASSERT(dirfd != NULL);
67 ASSERT(resolved_path != NULL);
68 if ((namespc == NULL) || (namespc->namespc() == kNone)) {
69 *dirfd = AT_FDCWD;
70 *resolved_path = path;
71 return false;
72 }
73 mxio_ns_t* ns = reinterpret_cast<mxio_ns_t*>(namespc->namespc());
74 *dirfd = mxio_ns_opendir(ns);
75 ASSERT(*dirfd >= 0);
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 true;
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_FUCHSIA)
OLDNEW
« no previous file with comments | « runtime/bin/namespace_android.cc ('k') | runtime/bin/namespace_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698