Chromium Code Reviews| 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 /** | 5 /** |
| 6 * [Directory] objects are used for working with directories. | 6 * [Directory] objects are used for working with directories. |
| 7 */ | 7 */ |
| 8 interface Directory default _Directory { | 8 interface Directory default _Directory { |
| 9 /** | 9 /** |
| 10 * Creates a directory object. The path is either a full path or | 10 * Creates a directory object. The path is either a full path or |
| 11 * relative to the directory in which the Dart VM was | 11 * relative to the directory in which the Dart VM was |
| 12 * started. | 12 * started. |
| 13 */ | 13 */ |
| 14 Directory(String path); | 14 Directory(String path); |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * Check whether a directory with this name already exists. If the | 17 * Check whether a directory with this name already exists. If the |
| 18 * operation completes successfully the [existsHandler] is called with | 18 * operation completes successfully the callback is called with the |
| 19 * the result. Otherwise the [errorHandler] is called. | 19 * result. Otherwise [onError] is called. |
| 20 */ | 20 */ |
| 21 void exists(); | 21 void exists(void callback(bool exists)); |
| 22 | 22 |
| 23 /** | 23 /** |
| 24 * Synchronously check whether a directory with this name already exists. | 24 * Synchronously check whether a directory with this name already exists. |
| 25 */ | 25 */ |
| 26 bool existsSync(); | 26 bool existsSync(); |
| 27 | 27 |
| 28 /** | 28 /** |
| 29 * Creates the directory with this name if it does not exist. | 29 * Creates the directory with this name if it does not exist. If |
| 30 * If the directory is successfully created the [createHandler] is | 30 * the directory is successfully created the callback is |
| 31 * called. Otherwise the [errorHandler] is called. | 31 * called. Otherwise [onError] is called. |
| 32 */ | 32 */ |
| 33 void create(); | 33 void create(void callback()); |
| 34 | 34 |
| 35 /** | 35 /** |
| 36 * Synchronously creates the directory with this name if it does not exist. | 36 * Synchronously creates the directory with this name if it does not exist. |
| 37 * Throws an exception if the directory already exists. | 37 * Throws an exception if the directory already exists. |
| 38 */ | 38 */ |
| 39 void createSync(); | 39 void createSync(); |
| 40 | 40 |
| 41 /** | 41 /** |
| 42 * Creates a temporary directory with a name based on the current path. | 42 * Creates a temporary directory with a name based on the current |
| 43 * This name and path is used as a template, and additional characters are | 43 * path. This name and path is used as a template, and additional |
| 44 * appended to it by the call to make a unique directory name. If the | 44 * characters are appended to it by the call to make a unique |
| 45 * path is the empty string, a default system temp directory and name | 45 * directory name. If the path is the empty string, a default |
| 46 * are used for the template. | 46 * system temp directory and name are used for the template. |
| 47 * The path is modified to be the path of the new directory. | 47 * |
| 48 * After the new directory is created, and the path modified, the callback | 48 * The path is modified to be the path of the new directory. After |
| 49 * createTempHandler will be called. The error handler is called if | 49 * the new directory is created, and the path modified, the callback |
| 50 * the temporary directory cannot be created. | 50 * will be called. The error handler is called if the temporary |
| 51 * directory cannot be created. | |
| 51 */ | 52 */ |
| 52 void createTemp(); | 53 void createTemp(void callback()); |
|
Søren Gjesse
2012/02/29 15:42:20
Maybe we should consider changing the behaviour of
| |
| 53 | 54 |
| 54 /** | 55 /** |
| 55 * Synchronously creates a temporary directory with a name based on the | 56 * Synchronously creates a temporary directory with a name based on the |
| 56 * current path. This name and path is used as a template, and additional | 57 * current path. This name and path is used as a template, and additional |
| 57 * characters are appended to it by the call to make a unique directory name. | 58 * characters are appended to it by the call to make a unique directory name. |
| 58 * If the path is the empty string, a default system temp directory and name | 59 * If the path is the empty string, a default system temp directory and name |
| 59 * are used for the template. | 60 * are used for the template. |
| 60 * The path is modified to be the path of the new directory. | 61 * The path is modified to be the path of the new directory. |
| 61 */ | 62 */ |
| 62 void createTempSync(); | 63 void createTempSync(); |
|
Søren Gjesse
2012/02/29 15:42:20
Then this should return a new Directory object.
| |
| 63 | 64 |
| 64 /** | 65 /** |
| 65 * Deletes the directory with this name. If the operation completes | 66 * Deletes the directory with this name. If the operation completes |
| 66 * successfully the [deleteHandler] is called. Otherwise the | 67 * successfully the callback is called. Otherwise [onError] is |
| 67 * [errorHandler] is called. | 68 * called. |
| 68 * | 69 * |
| 69 * If [recursive] is [:true:] this directory and all sub-directories | 70 * If [recursive] is [:true:] this directory and all sub-directories |
| 70 * and files in the directory are deleted. If [recursive] is | 71 * and files in the directory are deleted. If [recursive] is |
| 71 * [:false:] only this directory (which must be empty) is | 72 * [:false:] only this directory (which must be empty) is |
| 72 * deleted. [recursive] is [:false:] by default. | 73 * deleted. |
| 73 */ | 74 */ |
| 74 void delete([bool recursive]); | 75 void delete(bool recursive, void callback()); |
| 75 | 76 |
| 76 /** | 77 /** |
| 77 * Deletes the directory with this name. Throws an exception | 78 * Deletes the directory with this name. Throws an exception |
| 78 * if the directory cannot be deleted. | 79 * if the directory cannot be deleted. |
| 79 * | 80 * |
| 80 * If [recursive] is [:true:] this directory and all sub-directories | 81 * If [recursive] is [:true:] this directory and all sub-directories |
| 81 * and files in the directory are deleted. If [recursive] is | 82 * and files in the directory are deleted. If [recursive] is |
| 82 * [:false:] only this directory (which must be empty) is | 83 * [:false:] only this directory (which must be empty) is |
| 83 * deleted. [recursive] is [:false:] by default. | 84 * deleted. [recursive] is [:false:] by default. |
| 84 */ | 85 */ |
| 85 void deleteSync([bool recursive]); | 86 void deleteSync([bool recursive]); |
| 86 | 87 |
| 87 /** | 88 /** |
| 88 * List the sub-directories and files of this | 89 * List the sub-directories and files of this |
| 89 * [Directory]. Optionally recurse into sub-directories. For each | 90 * [Directory]. Optionally recurse into sub-directories. For each |
| 90 * file and directory, the file or directory handler is called. When | 91 * file and directory, the file or directory handler is called. When |
| 91 * all directories have been listed the done handler is called. If | 92 * all directories have been listed the done handler is called. If |
| 92 * the listing operation is recursive, the error handler is called | 93 * the listing operation is recursive, the error handler is called |
| 93 * if a subdirectory cannot be opened for listing. | 94 * if a subdirectory cannot be opened for listing. |
| 94 */ | 95 */ |
| 96 // TODO(ager): Should we change this to return an event emitting | |
| 97 // DirectoryLister object. Alternatively, pass in one callback that | |
| 98 // gets called with an indication of whether what it is called with | |
| 99 // is a file, a directory or an indication that the listing is over. | |
| 95 void list([bool recursive]); | 100 void list([bool recursive]); |
| 96 | 101 |
| 97 /** | 102 /** |
| 98 * Sets the directory handler that is called for all directories | 103 * Sets the directory handler that is called for all directories |
| 99 * during listing operations. The directory handler is called with | 104 * during listing operations. The directory handler is called with |
| 100 * the full path of the directory. | 105 * the full path of the directory. |
| 101 */ | 106 */ |
| 102 void set dirHandler(void dirHandler(String dir)); | 107 void set onDir(void onDir(String dir)); |
| 103 | 108 |
| 104 /** | 109 /** |
| 105 * Sets the handler that is called for all files during listing | 110 * Sets the handler that is called for all files during listing |
| 106 * operations. The file handler is called with the full path of the | 111 * operations. The file handler is called with the full path of the |
| 107 * file. | 112 * file. |
| 108 */ | 113 */ |
| 109 void set fileHandler(void fileHandler(String file)); | 114 void set onFile(void onFile(String file)); |
| 110 | 115 |
| 111 /** | 116 /** |
| 112 * Set the handler that is called when a directory listing is | 117 * Set the handler that is called when a directory listing is |
| 113 * done. The handler is called with an indication of whether or not | 118 * done. The handler is called with an indication of whether or not |
| 114 * the listing operation completed. | 119 * the listing operation completed. |
| 115 */ | 120 */ |
| 116 void set doneHandler(void doneHandler(bool completed)); | 121 void set onDone(void onDone(bool completed)); |
| 117 | |
| 118 /** | |
| 119 * Set the handler that is called when checking if a directory with this | |
| 120 * name exists. | |
| 121 */ | |
| 122 void set existsHandler(void existsHandler(bool exists)); | |
| 123 | |
| 124 /** | |
| 125 * Set the handler that is called when a directory is successfully created. | |
| 126 */ | |
| 127 void set createHandler(void createHandler()); | |
| 128 | |
| 129 /** | |
| 130 * Set the handler that is called when a temporary directory is | |
| 131 * successfully created. | |
| 132 */ | |
| 133 void set createTempHandler(void createTempHandler()); | |
| 134 | |
| 135 /** | |
| 136 * Set the handler that is called when a directory is successfully | |
| 137 * deleted. | |
| 138 */ | |
| 139 void set deleteHandler(void deleteHandler()); | |
| 140 | 122 |
| 141 /** | 123 /** |
| 142 * Sets the handler that is called if there is an error while listing | 124 * Sets the handler that is called if there is an error while listing |
| 143 * or creating directories. | 125 * or creating directories. |
| 144 */ | 126 */ |
| 145 void set errorHandler(void errorHandler(String error)); | 127 void set onError(void onError(String error)); |
| 146 | 128 |
| 147 /** | 129 /** |
| 148 * Gets the path of this directory. | 130 * Gets the path of this directory. |
| 149 */ | 131 */ |
| 150 final String path; | 132 final String path; |
| 151 } | 133 } |
| 152 | 134 |
| 153 | 135 |
| 154 class DirectoryException { | 136 class DirectoryException { |
| 155 const DirectoryException([String this.message, int this.errorCode = 0]); | 137 const DirectoryException([String this.message, int this.errorCode = 0]); |
| 156 String toString() => "DirectoryException: $message"; | 138 String toString() => "DirectoryException: $message"; |
| 157 final String message; | 139 final String message; |
| 158 final int errorCode; | 140 final int errorCode; |
| 159 } | 141 } |
| OLD | NEW |