| 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 function FileCopyManager(root) { | 5 function FileCopyManager(root) { |
| 6 this.copyTasks_ = []; | 6 this.copyTasks_ = []; |
| 7 this.cancelObservers_ = []; | 7 this.cancelObservers_ = []; |
| 8 this.cancelRequested_ = false; | 8 this.cancelRequested_ = false; |
| 9 this.root_ = root; | 9 this.root_ = root; |
| 10 } | 10 } |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 var added = 0; | 318 var added = 0; |
| 319 | 319 |
| 320 results.isCut = (clipboard.isCut == 'true'); | 320 results.isCut = (clipboard.isCut == 'true'); |
| 321 results.isOnGData = (clipboard.isOnGData == 'true'); | 321 results.isOnGData = (clipboard.isOnGData == 'true'); |
| 322 | 322 |
| 323 util.getDirectories(self.root_, {create: false}, directories, onEntryFound, | 323 util.getDirectories(self.root_, {create: false}, directories, onEntryFound, |
| 324 onPathError); | 324 onPathError); |
| 325 util.getFiles(self.root_, {create: false}, files, onEntryFound, | 325 util.getFiles(self.root_, {create: false}, files, onEntryFound, |
| 326 onPathError); | 326 onPathError); |
| 327 } | 327 } |
| 328 | 328 if (!clipboard.sourceDir) |
| 329 onSourceEntryFound(); |
| 330 else |
| 329 self.root_.getDirectory(clipboard.sourceDir, | 331 self.root_.getDirectory(clipboard.sourceDir, |
| 330 {create: false}, | 332 {create: false}, |
| 331 onSourceEntryFound, | 333 onSourceEntryFound, |
| 332 onPathError); | 334 onPathError); |
| 333 }; | 335 }; |
| 334 | 336 |
| 335 /** | 337 /** |
| 336 * Initiate a file copy. | 338 * Initiate a file copy. |
| 337 */ | 339 */ |
| 338 FileCopyManager.prototype.queueCopy = function(sourceDirEntry, | 340 FileCopyManager.prototype.queueCopy = function(sourceDirEntry, |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 | 486 |
| 485 var sourcePath = task.sourceDirEntry.fullPath; | 487 var sourcePath = task.sourceDirEntry.fullPath; |
| 486 if (sourceEntry.fullPath.substr(0, sourcePath.length) != sourcePath) { | 488 if (sourceEntry.fullPath.substr(0, sourcePath.length) != sourcePath) { |
| 487 // We found an entry in the list that is not relative to the base source | 489 // We found an entry in the list that is not relative to the base source |
| 488 // path, something is wrong. | 490 // path, something is wrong. |
| 489 return onError('UNEXPECTED_SOURCE_FILE', sourceEntry.fullPath); | 491 return onError('UNEXPECTED_SOURCE_FILE', sourceEntry.fullPath); |
| 490 } | 492 } |
| 491 | 493 |
| 492 var targetDirEntry = task.targetDirEntry; | 494 var targetDirEntry = task.targetDirEntry; |
| 493 var originalPath = sourceEntry.fullPath.substr(sourcePath.length + 1); | 495 var originalPath = sourceEntry.fullPath.substr(sourcePath.length + 1); |
| 496 |
| 497 // If the source entry is GData search result, we should not use the file name |
| 498 // we get from file entry (this will be in format |
| 499 // resource_id.original_file_name). Instead, we should use original_file_name. |
| 500 // Note that if the entry is GData search result, it can only be immediate |
| 501 // child of |task.sourceDirEntry|, so originalPath should be equal to |
| 502 // gdataSearchResult.fileName. |
| 503 var gdataSearchResult = |
| 504 util.getFileAndDisplayNameForGDataSearchResult(sourceEntry.fullPath); |
| 505 if (gdataSearchResult && originalPath != gdataSearchResult.displayName) { |
| 506 if (sourceEntry.isDirectory) { |
| 507 // We usually register paths relative to sourceDirEntry, but since the |
| 508 // entries for which we have to do this can only be immediate children of |
| 509 // the source dir, registering names should be fine. |
| 510 task.registerRename(gdataSearchResult.fileName, |
| 511 gdataSearchResult.displayName); |
| 512 } |
| 513 // Registered rename paths are appended '/', so we have to change |
| 514 // |originalPath| for directory entries too. |originalPath| won't be changed |
| 515 // during applyRenames (at least not by applying just registered rename). |
| 516 originalPath = gdataSearchResult.displayName; |
| 517 } |
| 518 |
| 494 originalPath = task.applyRenames(originalPath); | 519 originalPath = task.applyRenames(originalPath); |
| 495 | 520 |
| 496 var targetRelativePrefix = originalPath; | 521 var targetRelativePrefix = originalPath; |
| 497 var targetExt = ''; | 522 var targetExt = ''; |
| 498 var index = targetRelativePrefix.lastIndexOf('.'); | 523 var index = targetRelativePrefix.lastIndexOf('.'); |
| 499 if (index != -1) { | 524 if (index != -1) { |
| 500 targetExt = targetRelativePrefix.substr(index); | 525 targetExt = targetRelativePrefix.substr(index); |
| 501 targetRelativePrefix = targetRelativePrefix.substr(0, index); | 526 targetRelativePrefix = targetRelativePrefix.substr(0, index); |
| 502 } | 527 } |
| 503 | 528 |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 successCallback(targetEntry, file.size); | 750 successCallback(targetEntry, file.size); |
| 726 }; | 751 }; |
| 727 writer.write(file); | 752 writer.write(file); |
| 728 } | 753 } |
| 729 | 754 |
| 730 targetEntry.createWriter(onWriterCreated, errorCallback); | 755 targetEntry.createWriter(onWriterCreated, errorCallback); |
| 731 } | 756 } |
| 732 | 757 |
| 733 sourceEntry.file(onSourceFileFound, errorCallback); | 758 sourceEntry.file(onSourceFileFound, errorCallback); |
| 734 }; | 759 }; |
| OLD | NEW |