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

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

Issue 3007703002: [dart:io] Namespaces for file IO (Closed)
Patch Set: Remove namespace_unsupported.cc 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_fuchsia.cc ('k') | runtime/bin/namespace_macos.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_LINUX)
7
8 #include "bin/namespace.h"
9
10 #include <errno.h>
11 #include <fcntl.h>
12
13 #include "bin/fdutils.h"
14 #include "bin/file.h"
15 #include "platform/signal_blocker.h"
16
17 namespace dart {
18 namespace bin {
19
20 Namespace* Namespace::Create(const char* path) {
21 const intptr_t fd = TEMP_FAILURE_RETRY(open64(path, O_PATH));
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,
67 const char* path,
68 intptr_t* dirfd,
69 const char** resolved_path) {
70 ASSERT(dirfd != NULL);
71 ASSERT(resolved_path != NULL);
72 if ((namespc == NULL) || (namespc->namespc() == kNone)) {
73 *dirfd = AT_FDCWD;
74 *resolved_path = path;
75 return false;
76 }
77 *dirfd = namespc->namespc();
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 false;
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_LINUX)
OLDNEW
« no previous file with comments | « runtime/bin/namespace_fuchsia.cc ('k') | runtime/bin/namespace_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698