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 part of dart.io; | 5 part of dart.io; |
6 | 6 |
7 class _Directory implements Directory { | 7 class _Directory implements Directory { |
8 static const CREATE_REQUEST = 0; | 8 static const CREATE_REQUEST = 0; |
9 static const DELETE_REQUEST = 1; | 9 static const DELETE_REQUEST = 1; |
10 static const EXISTS_REQUEST = 2; | 10 static const EXISTS_REQUEST = 2; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 return new Future.immediate(notFound); | 74 return new Future.immediate(notFound); |
75 } else { | 75 } else { |
76 return future; | 76 return future; |
77 } | 77 } |
78 } | 78 } |
79 | 79 |
80 Future<Directory> createRecursively() { | 80 Future<Directory> createRecursively() { |
81 if (_path is !String) { | 81 if (_path is !String) { |
82 throw new ArgumentError(); | 82 throw new ArgumentError(); |
83 } | 83 } |
84 var path = new Path.fromNative(_path); | 84 var path = new Path(_path); |
85 var dirsToCreate = []; | 85 var dirsToCreate = []; |
86 var terminator = path.isAbsolute ? '/' : ''; | 86 var terminator = path.isAbsolute ? '/' : ''; |
87 while (path.toString() != terminator) { | 87 while (path.toString() != terminator) { |
88 dirsToCreate.add(new Directory.fromPath(path)); | 88 dirsToCreate.add(new Directory.fromPath(path)); |
89 path = path.directoryPath; | 89 path = path.directoryPath; |
90 } | 90 } |
91 return _computeExistingIndex(dirsToCreate).then((index) { | 91 return _computeExistingIndex(dirsToCreate).then((index) { |
92 var future; | 92 var future; |
93 for (var i = index - 1; i >= 0 ; i--) { | 93 for (var i = index - 1; i >= 0 ; i--) { |
94 if (future == null) { | 94 if (future == null) { |
(...skipping 20 matching lines...) Expand all Loading... |
115 request[1] = _path; | 115 request[1] = _path; |
116 return _directoryService.call(request).then((response) { | 116 return _directoryService.call(request).then((response) { |
117 if (_isErrorResponse(response)) { | 117 if (_isErrorResponse(response)) { |
118 throw _exceptionOrErrorFromResponse(response, "Creation failed"); | 118 throw _exceptionOrErrorFromResponse(response, "Creation failed"); |
119 } | 119 } |
120 return this; | 120 return this; |
121 }); | 121 }); |
122 } | 122 } |
123 | 123 |
124 void createRecursivelySync() { | 124 void createRecursivelySync() { |
125 var path = new Path.fromNative(_path); | 125 var path = new Path(_path); |
126 var dirsToCreate = []; | 126 var dirsToCreate = []; |
127 var terminator = path.isAbsolute ? '/' : ''; | 127 var terminator = path.isAbsolute ? '/' : ''; |
128 while (path.toString() != terminator) { | 128 while (path.toString() != terminator) { |
129 var dir = new Directory.fromPath(path); | 129 var dir = new Directory.fromPath(path); |
130 if (dir.existsSync()) break; | 130 if (dir.existsSync()) break; |
131 dirsToCreate.add(dir); | 131 dirsToCreate.add(dir); |
132 path = path.directoryPath; | 132 path = path.directoryPath; |
133 } | 133 } |
134 for (var i = dirsToCreate.length - 1; i >= 0; i--) { | 134 for (var i = dirsToCreate.length - 1; i >= 0; i--) { |
135 dirsToCreate[i].createSync(); | 135 dirsToCreate[i].createSync(); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 } else { | 351 } else { |
352 throw e; | 352 throw e; |
353 } | 353 } |
354 } | 354 } |
355 | 355 |
356 Function _onDir; | 356 Function _onDir; |
357 Function _onFile; | 357 Function _onFile; |
358 Function _onDone; | 358 Function _onDone; |
359 Function _onError; | 359 Function _onError; |
360 } | 360 } |
OLD | NEW |