OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** | 7 /** |
8 * Namespace for utility functions. | 8 * Namespace for utility functions. |
9 */ | 9 */ |
10 var util = {}; | 10 var util = {}; |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 // Found a path that doesn't exist. | 498 // Found a path that doesn't exist. |
499 onSuccess(trialPath); | 499 onSuccess(trialPath); |
500 } | 500 } |
501 | 501 |
502 var numRetry = MAX_RETRY; | 502 var numRetry = MAX_RETRY; |
503 var onResolved = function(entry) { | 503 var onResolved = function(entry) { |
504 if (--numRetry == 0) { | 504 if (--numRetry == 0) { |
505 // Hit the limit of the number of retrial. | 505 // Hit the limit of the number of retrial. |
506 // Note that we cannot create FileError object directly, so here we use | 506 // Note that we cannot create FileError object directly, so here we use |
507 // Object.create instead. | 507 // Object.create instead. |
508 onError(Object.create(FileError.prototype, { | 508 onError(util.createFileError(FileError.PATH_EXISTS_ERR)); |
509 code: { | |
510 get: function() { return FileError.PATH_EXISTS_ERR; } | |
511 } | |
512 })); | |
513 return; | 509 return; |
514 } | 510 } |
515 | 511 |
516 ++copyNumber; | 512 ++copyNumber; |
517 trialPath = prefix + ' (' + copyNumber + ')' + ext; | 513 trialPath = prefix + ' (' + copyNumber + ')' + ext; |
518 util.resolvePath(dirEntry, trialPath, onResolved, onNotResolved); | 514 util.resolvePath(dirEntry, trialPath, onResolved, onNotResolved); |
519 }; | 515 }; |
520 | 516 |
521 // Check to see if the target exists. | 517 // Check to see if the target exists. |
522 util.resolvePath(dirEntry, trialPath, onResolved, onNotResolved); | 518 util.resolvePath(dirEntry, trialPath, onResolved, onNotResolved); |
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1151 }; | 1147 }; |
1152 | 1148 |
1153 /** | 1149 /** |
1154 * The type of an entry changed event. | 1150 * The type of an entry changed event. |
1155 * @enum {number} | 1151 * @enum {number} |
1156 */ | 1152 */ |
1157 util.EntryChangedType = { | 1153 util.EntryChangedType = { |
1158 CREATED: 0, | 1154 CREATED: 0, |
1159 DELETED: 1, | 1155 DELETED: 1, |
1160 }; | 1156 }; |
| 1157 |
| 1158 |
| 1159 /** |
| 1160 * Creates a FileError instance with given code. |
| 1161 * Note that we cannot create FileError instance by "new FileError(code)", |
| 1162 * unfortunately, so here we use Object.create. |
| 1163 * @param {number} code Error code for the FileError. |
| 1164 * @return {FileError} FileError instance |
| 1165 */ |
| 1166 util.createFileError = function(code) { |
| 1167 return Object.create(FileError.prototype, { |
| 1168 code: { get: function() { return code; } } |
| 1169 }); |
| 1170 }; |
OLD | NEW |