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 extends FileSystemEntity implements Directory { | 7 class _Directory extends FileSystemEntity implements Directory { |
8 final String path; | 8 final String path; |
9 | 9 |
10 _Directory(String this.path) { | 10 _Directory(String this.path) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 } | 84 } |
85 } | 85 } |
86 if (future == null) { | 86 if (future == null) { |
87 return new Future.value(notFound); | 87 return new Future.value(notFound); |
88 } else { | 88 } else { |
89 return future; | 89 return future; |
90 } | 90 } |
91 } | 91 } |
92 | 92 |
93 Future<Directory> createRecursively() { | 93 Future<Directory> createRecursively() { |
94 var path = new _Path(this.path); | |
95 var dirsToCreate = []; | 94 var dirsToCreate = []; |
96 var terminator = path.isAbsolute ? '/' : ''; | 95 var dir = this; |
97 while (path.toString() != terminator) { | 96 while (dir.path != dir.parent.path) { |
98 dirsToCreate.add(new Directory(path.toNativePath())); | 97 dirsToCreate.add(dir); |
99 path = path.directoryPath; | 98 dir = dir.parent; |
100 } | 99 } |
101 return _computeExistingIndex(dirsToCreate).then((index) { | 100 return _computeExistingIndex(dirsToCreate).then((index) { |
102 var future; | 101 var future; |
103 for (var i = index - 1; i >= 0 ; i--) { | 102 for (var i = index - 1; i >= 0 ; i--) { |
104 if (future == null) { | 103 if (future == null) { |
105 future = dirsToCreate[i].create(); | 104 future = dirsToCreate[i].create(); |
106 } else { | 105 } else { |
107 future = future.then((_) { | 106 future = future.then((_) { |
108 return dirsToCreate[i].create(); | 107 return dirsToCreate[i].create(); |
109 }); | 108 }); |
(...skipping 11 matching lines...) Expand all Loading... |
121 if (recursive) return createRecursively(); | 120 if (recursive) return createRecursively(); |
122 return _IOService.dispatch(_DIRECTORY_CREATE, [path]).then((response) { | 121 return _IOService.dispatch(_DIRECTORY_CREATE, [path]).then((response) { |
123 if (_isErrorResponse(response)) { | 122 if (_isErrorResponse(response)) { |
124 throw _exceptionOrErrorFromResponse(response, "Creation failed"); | 123 throw _exceptionOrErrorFromResponse(response, "Creation failed"); |
125 } | 124 } |
126 return this; | 125 return this; |
127 }); | 126 }); |
128 } | 127 } |
129 | 128 |
130 void createRecursivelySync() { | 129 void createRecursivelySync() { |
131 var path = new _Path(this.path); | 130 var dir = this; |
132 var dirsToCreate = []; | 131 var dirsToCreate = []; |
133 var terminator = path.isAbsolute ? '/' : ''; | 132 while (dir.path != dir.parent.path) { |
134 while (path.toString() != terminator) { | |
135 var dir = new Directory(path.toNativePath()); | |
136 if (dir.existsSync()) break; | 133 if (dir.existsSync()) break; |
137 dirsToCreate.add(dir); | 134 dirsToCreate.add(dir); |
138 path = path.directoryPath; | 135 dir = dir.parent; |
139 } | 136 } |
140 for (var i = dirsToCreate.length - 1; i >= 0; i--) { | 137 for (var i = dirsToCreate.length - 1; i >= 0; i--) { |
141 dirsToCreate[i].createSync(); | 138 dirsToCreate[i].createSync(); |
142 } | 139 } |
143 } | 140 } |
144 | 141 |
145 void createSync({bool recursive: false}) { | 142 void createSync({bool recursive: false}) { |
146 if (recursive) return createRecursivelySync(); | 143 if (recursive) return createRecursivelySync(); |
147 var result = _create(path); | 144 var result = _create(path); |
148 if (result is OSError) { | 145 if (result is OSError) { |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 controller.addError( | 393 controller.addError( |
397 new DirectoryException("Directory listing failed", | 394 new DirectoryException("Directory listing failed", |
398 errorPath, | 395 errorPath, |
399 err)); | 396 err)); |
400 } else { | 397 } else { |
401 controller.addError( | 398 controller.addError( |
402 new DirectoryException("Internal error")); | 399 new DirectoryException("Internal error")); |
403 } | 400 } |
404 } | 401 } |
405 } | 402 } |
OLD | NEW |