OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef RUNTIME_BIN_FILE_H_ | 5 #ifndef RUNTIME_BIN_FILE_H_ |
6 #define RUNTIME_BIN_FILE_H_ | 6 #define RUNTIME_BIN_FILE_H_ |
7 | 7 |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <string.h> | 10 #include <string.h> |
11 #include <sys/types.h> | 11 #include <sys/types.h> |
12 | 12 |
13 #include "bin/builtin.h" | 13 #include "bin/builtin.h" |
14 #include "bin/dartutils.h" | 14 #include "bin/dartutils.h" |
15 #include "bin/log.h" | 15 #include "bin/log.h" |
| 16 #include "bin/namespace.h" |
16 #include "bin/reference_counting.h" | 17 #include "bin/reference_counting.h" |
17 | 18 |
18 namespace dart { | 19 namespace dart { |
19 namespace bin { | 20 namespace bin { |
20 | 21 |
21 // Forward declaration. | 22 // Forward declaration. |
22 class FileHandle; | 23 class FileHandle; |
23 | 24 |
24 class MappedMemory { | 25 class MappedMemory { |
25 public: | 26 public: |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 void DeleteWeakHandle(Dart_Isolate isolate) { | 166 void DeleteWeakHandle(Dart_Isolate isolate) { |
166 Dart_DeleteWeakPersistentHandle(isolate, weak_handle_); | 167 Dart_DeleteWeakPersistentHandle(isolate, weak_handle_); |
167 weak_handle_ = NULL; | 168 weak_handle_ = NULL; |
168 } | 169 } |
169 | 170 |
170 // Open the file with the given path. The file is always opened for | 171 // Open the file with the given path. The file is always opened for |
171 // reading. If mode contains kWrite the file is opened for both | 172 // reading. If mode contains kWrite the file is opened for both |
172 // reading and writing. If mode contains kWrite and the file does | 173 // reading and writing. If mode contains kWrite and the file does |
173 // not exist the file is created. The file is truncated to length 0 if | 174 // not exist the file is created. The file is truncated to length 0 if |
174 // mode contains kTruncate. Assumes we are in an API scope. | 175 // mode contains kTruncate. Assumes we are in an API scope. |
175 static File* Open(const char* path, FileOpenMode mode); | 176 static File* Open(Namespace* namespc, const char* path, FileOpenMode mode); |
176 | 177 |
177 // Create a file object for the specified stdio file descriptor | 178 // Create a file object for the specified stdio file descriptor |
178 // (stdin, stout or stderr). | 179 // (stdin, stout or stderr). |
179 static File* OpenStdio(int fd); | 180 static File* OpenStdio(int fd); |
180 | 181 |
181 static bool Exists(const char* path); | 182 static bool Exists(Namespace* namespc, const char* path); |
182 static bool Create(const char* path); | 183 static bool Create(Namespace* namespc, const char* path); |
183 static bool CreateLink(const char* path, const char* target); | 184 static bool CreateLink(Namespace* namespc, |
184 static bool Delete(const char* path); | 185 const char* path, |
185 static bool DeleteLink(const char* path); | 186 const char* target); |
186 static bool Rename(const char* old_path, const char* new_path); | 187 static bool Delete(Namespace* namespc, const char* path); |
187 static bool RenameLink(const char* old_path, const char* new_path); | 188 static bool DeleteLink(Namespace* namespc, const char* path); |
188 static bool Copy(const char* old_path, const char* new_path); | 189 static bool Rename(Namespace* namespc, |
189 static int64_t LengthFromPath(const char* path); | 190 const char* old_path, |
190 static void Stat(const char* path, int64_t* data); | 191 const char* new_path); |
191 static time_t LastModified(const char* path); | 192 static bool RenameLink(Namespace* namespc, |
192 static bool SetLastModified(const char* path, int64_t millis); | 193 const char* old_path, |
193 static time_t LastAccessed(const char* path); | 194 const char* new_path); |
194 static bool SetLastAccessed(const char* path, int64_t millis); | 195 static bool Copy(Namespace* namespc, |
| 196 const char* old_path, |
| 197 const char* new_path); |
| 198 static int64_t LengthFromPath(Namespace* namespc, const char* path); |
| 199 static void Stat(Namespace* namespc, const char* path, int64_t* data); |
| 200 static time_t LastModified(Namespace* namespc, const char* path); |
| 201 static bool SetLastModified(Namespace* namespc, |
| 202 const char* path, |
| 203 int64_t millis); |
| 204 static time_t LastAccessed(Namespace* namespc, const char* path); |
| 205 static bool SetLastAccessed(Namespace* namespc, |
| 206 const char* path, |
| 207 int64_t millis); |
195 static bool IsAbsolutePath(const char* path); | 208 static bool IsAbsolutePath(const char* path); |
196 static const char* PathSeparator(); | 209 static const char* PathSeparator(); |
197 static const char* StringEscapedPathSeparator(); | 210 static const char* StringEscapedPathSeparator(); |
198 static Type GetType(const char* path, bool follow_links); | 211 static Type GetType(Namespace* namespc, const char* path, bool follow_links); |
199 static Identical AreIdentical(const char* file_1, const char* file_2); | 212 static Identical AreIdentical(Namespace* namespc, |
| 213 const char* file_1, |
| 214 const char* file_2); |
200 static StdioHandleType GetStdioHandleType(int fd); | 215 static StdioHandleType GetStdioHandleType(int fd); |
201 | 216 |
202 // LinkTarget and GetCanonicalPath may call Dart_ScopeAllocate. | 217 // LinkTarget, GetCanonicalPath, and ReadLink may call Dart_ScopeAllocate. |
203 static const char* LinkTarget(const char* pathname); | 218 static const char* LinkTarget(Namespace* namespc, const char* pathname); |
204 static const char* GetCanonicalPath(const char* path); | 219 static const char* GetCanonicalPath(Namespace* namespc, const char* path); |
| 220 // Link LinkTarget, but pathname must be absolute. |
| 221 static const char* ReadLink(const char* pathname); |
205 | 222 |
206 static FileOpenMode DartModeToFileMode(DartFileOpenMode mode); | 223 static FileOpenMode DartModeToFileMode(DartFileOpenMode mode); |
207 | 224 |
208 static CObject* ExistsRequest(const CObjectArray& request); | 225 static CObject* ExistsRequest(const CObjectArray& request); |
209 static CObject* CreateRequest(const CObjectArray& request); | 226 static CObject* CreateRequest(const CObjectArray& request); |
210 static CObject* DeleteRequest(const CObjectArray& request); | 227 static CObject* DeleteRequest(const CObjectArray& request); |
211 static CObject* RenameRequest(const CObjectArray& request); | 228 static CObject* RenameRequest(const CObjectArray& request); |
212 static CObject* CopyRequest(const CObjectArray& request); | 229 static CObject* CopyRequest(const CObjectArray& request); |
213 static CObject* OpenRequest(const CObjectArray& request); | 230 static CObject* OpenRequest(const CObjectArray& request); |
214 static CObject* ResolveSymbolicLinksRequest(const CObjectArray& request); | 231 static CObject* ResolveSymbolicLinksRequest(const CObjectArray& request); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 Dart_WeakPersistentHandle weak_handle_; | 273 Dart_WeakPersistentHandle weak_handle_; |
257 | 274 |
258 friend class ReferenceCounted<File>; | 275 friend class ReferenceCounted<File>; |
259 DISALLOW_COPY_AND_ASSIGN(File); | 276 DISALLOW_COPY_AND_ASSIGN(File); |
260 }; | 277 }; |
261 | 278 |
262 } // namespace bin | 279 } // namespace bin |
263 } // namespace dart | 280 } // namespace dart |
264 | 281 |
265 #endif // RUNTIME_BIN_FILE_H_ | 282 #endif // RUNTIME_BIN_FILE_H_ |
OLD | NEW |