| 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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 310               path, {create: false}, | 310               path, {create: false}, | 
| 311               resultCallback, | 311               resultCallback, | 
| 312               errorCallback); | 312               errorCallback); | 
| 313         } else { | 313         } else { | 
| 314           errorCallback(err); | 314           errorCallback(err); | 
| 315         } | 315         } | 
| 316       }); | 316       }); | 
| 317 }; | 317 }; | 
| 318 | 318 | 
| 319 /** | 319 /** | 
| 320  * Locate the file referred to by path, creating directories or the file |  | 
| 321  * itself if necessary. |  | 
| 322  * @param {DirEntry} root The root entry. |  | 
| 323  * @param {string} path The file path. |  | 
| 324  * @param {function(FileEntry)} successCallback The callback. |  | 
| 325  * @param {function(FileError)} errorCallback The callback. |  | 
| 326  */ |  | 
| 327 util.getOrCreateFile = function(root, path, successCallback, errorCallback) { |  | 
| 328   var dirname = null; |  | 
| 329   var basename = null; |  | 
| 330 |  | 
| 331   var onDirFound = function(dirEntry) { |  | 
| 332     dirEntry.getFile(basename, { create: true }, |  | 
| 333                      successCallback, errorCallback); |  | 
| 334   }; |  | 
| 335 |  | 
| 336   var i = path.lastIndexOf('/'); |  | 
| 337   if (i > -1) { |  | 
| 338     dirname = path.substr(0, i); |  | 
| 339     basename = path.substr(i + 1); |  | 
| 340   } else { |  | 
| 341     basename = path; |  | 
| 342   } |  | 
| 343 |  | 
| 344   if (!dirname) { |  | 
| 345     onDirFound(root); |  | 
| 346     return; |  | 
| 347   } |  | 
| 348 |  | 
| 349   util.getOrCreateDirectory(root, dirname, onDirFound, errorCallback); |  | 
| 350 }; |  | 
| 351 |  | 
| 352 /** |  | 
| 353  * Locate the directory referred to by path, creating directories along the |  | 
| 354  * way. |  | 
| 355  * @param {DirEntry} root The root entry. |  | 
| 356  * @param {string} path The directory path. |  | 
| 357  * @param {function(FileEntry)} successCallback The callback. |  | 
| 358  * @param {function(FileError)} errorCallback The callback. |  | 
| 359  */ |  | 
| 360 util.getOrCreateDirectory = function(root, path, successCallback, |  | 
| 361                                      errorCallback) { |  | 
| 362   var names = path.split('/'); |  | 
| 363 |  | 
| 364   var getOrCreateNextName = function(dir) { |  | 
| 365     if (!names.length) |  | 
| 366       return successCallback(dir); |  | 
| 367 |  | 
| 368     var name; |  | 
| 369     do { |  | 
| 370       name = names.shift(); |  | 
| 371     } while (!name || name == '.'); |  | 
| 372 |  | 
| 373     dir.getDirectory(name, { create: true }, getOrCreateNextName, |  | 
| 374                      errorCallback); |  | 
| 375   }; |  | 
| 376 |  | 
| 377   getOrCreateNextName(root); |  | 
| 378 }; |  | 
| 379 |  | 
| 380 /** |  | 
| 381  * Renames the entry to newName. | 320  * Renames the entry to newName. | 
| 382  * @param {Entry} entry The entry to be renamed. | 321  * @param {Entry} entry The entry to be renamed. | 
| 383  * @param {string} newName The new name. | 322  * @param {string} newName The new name. | 
| 384  * @param {function(Entry)} successCallback Callback invoked when the rename | 323  * @param {function(Entry)} successCallback Callback invoked when the rename | 
| 385  *     is successfully done. | 324  *     is successfully done. | 
| 386  * @param {function(FileError)} errorCallback Callback invoked when an error | 325  * @param {function(FileError)} errorCallback Callback invoked when an error | 
| 387  *     is found. | 326  *     is found. | 
| 388  */ | 327  */ | 
| 389 util.rename = function(entry, newName, successCallback, errorCallback) { | 328 util.rename = function(entry, newName, successCallback, errorCallback) { | 
| 390   entry.getParent(function(parent) { | 329   entry.getParent(function(parent) { | 
| (...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1297  * @enum {string} | 1236  * @enum {string} | 
| 1298  * @const | 1237  * @const | 
| 1299  */ | 1238  */ | 
| 1300 util.VolumeType = Object.freeze({ | 1239 util.VolumeType = Object.freeze({ | 
| 1301   DRIVE: 'drive', | 1240   DRIVE: 'drive', | 
| 1302   DOWNLOADS: 'downloads', | 1241   DOWNLOADS: 'downloads', | 
| 1303   REMOVABLE: 'removable', | 1242   REMOVABLE: 'removable', | 
| 1304   ARCHIVE: 'archive', | 1243   ARCHIVE: 'archive', | 
| 1305   CLOUD_DEVICE: 'cloud_device' | 1244   CLOUD_DEVICE: 'cloud_device' | 
| 1306 }); | 1245 }); | 
| OLD | NEW | 
|---|