OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #include "bin/directory.h" | 5 #include "bin/directory.h" |
6 | 6 |
7 #include "bin/dartutils.h" | 7 #include "bin/dartutils.h" |
8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 | 10 |
11 | 11 |
12 namespace dart { | 12 namespace dart { |
13 namespace bin { | 13 namespace bin { |
14 | 14 |
15 void FUNCTION_NAME(Directory_Current)(Dart_NativeArguments args) { | 15 void FUNCTION_NAME(Directory_Current)(Dart_NativeArguments args) { |
16 char* current = Directory::Current(); | 16 char* current = Directory::Current(); |
17 if (current != NULL) { | 17 if (current != NULL) { |
18 Dart_SetReturnValue(args, DartUtils::NewString(current)); | 18 Dart_SetReturnValue(args, DartUtils::NewString(current)); |
19 free(current); | 19 free(current); |
20 } else { | 20 } else { |
21 Dart_Handle err = DartUtils::NewDartOSError(); | 21 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
22 if (Dart_IsError(err)) Dart_PropagateError(err); | |
23 Dart_SetReturnValue(args, err); | |
24 } | 22 } |
25 } | 23 } |
26 | 24 |
27 | 25 |
28 void FUNCTION_NAME(Directory_SetCurrent)(Dart_NativeArguments args) { | 26 void FUNCTION_NAME(Directory_SetCurrent)(Dart_NativeArguments args) { |
29 int argc = Dart_GetNativeArgumentCount(args); | 27 int argc = Dart_GetNativeArgumentCount(args); |
30 Dart_Handle path; | 28 Dart_Handle path; |
31 if (argc == 1) { | 29 if (argc == 1) { |
32 path = Dart_GetNativeArgument(args, 0); | 30 path = Dart_GetNativeArgument(args, 0); |
33 } | 31 } |
34 if (argc != 1 || !Dart_IsString(path)) { | 32 if (argc != 1 || !Dart_IsString(path)) { |
35 Dart_SetReturnValue(args, DartUtils::NewDartArgumentError(NULL)); | 33 Dart_SetReturnValue(args, DartUtils::NewDartArgumentError(NULL)); |
36 } else { | 34 } else { |
37 if (Directory::SetCurrent(DartUtils::GetStringValue(path))) { | 35 if (Directory::SetCurrent(DartUtils::GetStringValue(path))) { |
38 Dart_SetReturnValue(args, Dart_True()); | 36 Dart_SetReturnValue(args, Dart_True()); |
39 } else { | 37 } else { |
40 Dart_Handle err = DartUtils::NewDartOSError(); | 38 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
41 if (Dart_IsError(err)) Dart_PropagateError(err); | |
42 Dart_SetReturnValue(args, err); | |
43 } | 39 } |
44 } | 40 } |
45 } | 41 } |
46 | 42 |
47 | 43 |
48 void FUNCTION_NAME(Directory_Exists)(Dart_NativeArguments args) { | 44 void FUNCTION_NAME(Directory_Exists)(Dart_NativeArguments args) { |
49 static const int kExists = 1; | 45 static const int kExists = 1; |
50 static const int kDoesNotExist = 0; | 46 static const int kDoesNotExist = 0; |
51 Dart_Handle path = Dart_GetNativeArgument(args, 0); | 47 Dart_Handle path = Dart_GetNativeArgument(args, 0); |
52 Directory::ExistsResult result = | 48 Directory::ExistsResult result = |
53 Directory::Exists(DartUtils::GetStringValue(path)); | 49 Directory::Exists(DartUtils::GetStringValue(path)); |
54 if (result == Directory::EXISTS) { | 50 if (result == Directory::EXISTS) { |
55 Dart_SetReturnValue(args, Dart_NewInteger(kExists)); | 51 Dart_SetReturnValue(args, Dart_NewInteger(kExists)); |
56 } else if (result == Directory::DOES_NOT_EXIST) { | 52 } else if (result == Directory::DOES_NOT_EXIST) { |
57 Dart_SetReturnValue(args, Dart_NewInteger(kDoesNotExist)); | 53 Dart_SetReturnValue(args, Dart_NewInteger(kDoesNotExist)); |
58 } else { | 54 } else { |
59 Dart_Handle err = DartUtils::NewDartOSError(); | 55 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
60 if (Dart_IsError(err)) Dart_PropagateError(err); | |
61 Dart_SetReturnValue(args, err); | |
62 } | 56 } |
63 } | 57 } |
64 | 58 |
65 | 59 |
66 void FUNCTION_NAME(Directory_Create)(Dart_NativeArguments args) { | 60 void FUNCTION_NAME(Directory_Create)(Dart_NativeArguments args) { |
67 Dart_Handle path = Dart_GetNativeArgument(args, 0); | 61 Dart_Handle path = Dart_GetNativeArgument(args, 0); |
68 if (Directory::Create(DartUtils::GetStringValue(path))) { | 62 if (Directory::Create(DartUtils::GetStringValue(path))) { |
69 Dart_SetReturnValue(args, Dart_True()); | 63 Dart_SetReturnValue(args, Dart_True()); |
70 } else { | 64 } else { |
71 Dart_Handle err = DartUtils::NewDartOSError(); | 65 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
72 if (Dart_IsError(err)) Dart_PropagateError(err); | |
73 Dart_SetReturnValue(args, err); | |
74 } | 66 } |
75 } | 67 } |
76 | 68 |
77 | 69 |
78 void FUNCTION_NAME(Directory_SystemTemp)( | 70 void FUNCTION_NAME(Directory_SystemTemp)( |
79 Dart_NativeArguments args) { | 71 Dart_NativeArguments args) { |
80 char* result = Directory::SystemTemp(); | 72 char* result = Directory::SystemTemp(); |
81 Dart_SetReturnValue(args, DartUtils::NewString(result)); | 73 Dart_SetReturnValue(args, DartUtils::NewString(result)); |
82 free(result); | 74 free(result); |
83 } | 75 } |
84 | 76 |
85 | 77 |
86 void FUNCTION_NAME(Directory_CreateTemp)(Dart_NativeArguments args) { | 78 void FUNCTION_NAME(Directory_CreateTemp)(Dart_NativeArguments args) { |
87 Dart_Handle path = Dart_GetNativeArgument(args, 0); | 79 Dart_Handle path = Dart_GetNativeArgument(args, 0); |
88 if (!Dart_IsString(path)) { | 80 if (!Dart_IsString(path)) { |
89 Dart_SetReturnValue(args, DartUtils::NewDartArgumentError( | 81 Dart_SetReturnValue(args, DartUtils::NewDartArgumentError( |
90 "Prefix argument of CreateSystemTempSync is not a String")); | 82 "Prefix argument of CreateSystemTempSync is not a String")); |
91 return; | 83 return; |
92 } | 84 } |
93 char* result = Directory::CreateTemp(DartUtils::GetStringValue(path)); | 85 char* result = Directory::CreateTemp(DartUtils::GetStringValue(path)); |
94 if (result != NULL) { | 86 if (result != NULL) { |
95 Dart_SetReturnValue(args, DartUtils::NewString(result)); | 87 Dart_SetReturnValue(args, DartUtils::NewString(result)); |
96 free(result); | 88 free(result); |
97 } else { | 89 } else { |
98 Dart_Handle err = DartUtils::NewDartOSError(); | 90 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
99 if (Dart_IsError(err)) Dart_PropagateError(err); | |
100 Dart_SetReturnValue(args, err); | |
101 } | 91 } |
102 } | 92 } |
103 | 93 |
104 | 94 |
105 void FUNCTION_NAME(Directory_Delete)(Dart_NativeArguments args) { | 95 void FUNCTION_NAME(Directory_Delete)(Dart_NativeArguments args) { |
106 Dart_Handle path = Dart_GetNativeArgument(args, 0); | 96 Dart_Handle path = Dart_GetNativeArgument(args, 0); |
107 Dart_Handle recursive = Dart_GetNativeArgument(args, 1); | 97 Dart_Handle recursive = Dart_GetNativeArgument(args, 1); |
108 if (Directory::Delete(DartUtils::GetStringValue(path), | 98 if (Directory::Delete(DartUtils::GetStringValue(path), |
109 DartUtils::GetBooleanValue(recursive))) { | 99 DartUtils::GetBooleanValue(recursive))) { |
110 Dart_SetReturnValue(args, Dart_True()); | 100 Dart_SetReturnValue(args, Dart_True()); |
111 } else { | 101 } else { |
112 Dart_Handle err = DartUtils::NewDartOSError(); | 102 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
113 if (Dart_IsError(err)) Dart_PropagateError(err); | |
114 Dart_SetReturnValue(args, err); | |
115 } | 103 } |
116 } | 104 } |
117 | 105 |
118 | 106 |
119 void FUNCTION_NAME(Directory_Rename)(Dart_NativeArguments args) { | 107 void FUNCTION_NAME(Directory_Rename)(Dart_NativeArguments args) { |
120 Dart_Handle path = Dart_GetNativeArgument(args, 0); | 108 Dart_Handle path = Dart_GetNativeArgument(args, 0); |
121 Dart_Handle newPath = Dart_GetNativeArgument(args, 1); | 109 Dart_Handle newPath = Dart_GetNativeArgument(args, 1); |
122 if (Directory::Rename(DartUtils::GetStringValue(path), | 110 if (Directory::Rename(DartUtils::GetStringValue(path), |
123 DartUtils::GetStringValue(newPath))) { | 111 DartUtils::GetStringValue(newPath))) { |
124 Dart_SetReturnValue(args, Dart_True()); | 112 Dart_SetReturnValue(args, Dart_True()); |
125 } else { | 113 } else { |
126 Dart_Handle err = DartUtils::NewDartOSError(); | 114 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
127 if (Dart_IsError(err)) Dart_PropagateError(err); | |
128 Dart_SetReturnValue(args, err); | |
129 } | 115 } |
130 } | 116 } |
131 | 117 |
132 | 118 |
133 void FUNCTION_NAME(Directory_List)(Dart_NativeArguments args) { | 119 void FUNCTION_NAME(Directory_List)(Dart_NativeArguments args) { |
134 Dart_Handle path = Dart_GetNativeArgument(args, 0); | 120 Dart_Handle path = Dart_GetNativeArgument(args, 0); |
135 Dart_Handle recursive = Dart_GetNativeArgument(args, 1); | 121 Dart_Handle recursive = Dart_GetNativeArgument(args, 1); |
136 // Create the list to hold the directory listing here, and pass it to the | 122 // Create the list to hold the directory listing here, and pass it to the |
137 // SyncDirectoryListing object, which adds elements to it. | 123 // SyncDirectoryListing object, which adds elements to it. |
138 Dart_Handle follow_links = Dart_GetNativeArgument(args, 2); | 124 Dart_Handle follow_links = Dart_GetNativeArgument(args, 2); |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 if (listing->error()) { | 407 if (listing->error()) { |
422 listing->HandleError("Invalid path"); | 408 listing->HandleError("Invalid path"); |
423 listing->HandleDone(); | 409 listing->HandleDone(); |
424 } else { | 410 } else { |
425 while (ListNext(listing)) {} | 411 while (ListNext(listing)) {} |
426 } | 412 } |
427 } | 413 } |
428 | 414 |
429 } // namespace bin | 415 } // namespace bin |
430 } // namespace dart | 416 } // namespace dart |
OLD | NEW |