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

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

Issue 3007703002: [dart:io] Namespaces for file IO (Closed)
Patch Set: 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
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/fdutils.h"
15 #include "bin/file.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,
65 const char* path,
66 intptr_t* dirfd,
67 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 mxio_ns_t* ns = reinterpret_cast<mxio_ns_t*>(namespc->namespc());
76 *dirfd = mxio_ns_opendir(ns);
77 ASSERT(*dirfd >= 0);
78 if (File::IsAbsolutePath(path)) {
79 if (strcmp(path, File::PathSeparator()) == 0) {
80 *resolved_path = ".";
81 } else {
82 *resolved_path = &path[1];
83 }
84 } else {
85 *resolved_path = path;
86 }
87 return true;
88 }
89
90 NamespaceScope::NamespaceScope(Namespace* namespc, const char* path) {
91 owns_fd_ = Namespace::ResolvePath(namespc, path, &fd_, &path_);
92 }
93
94 NamespaceScope::~NamespaceScope() {
95 if (owns_fd_) {
96 FDUtils::SaveErrorAndClose(fd_);
97 }
98 }
99
100 } // namespace bin
101 } // namespace dart
102
103 #endif // defined(HOST_OS_FUCHSIA)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698