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 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 | 484 |
485 var sourcePath = task.sourceDirEntry.fullPath; | 485 var sourcePath = task.sourceDirEntry.fullPath; |
486 if (sourceEntry.fullPath.substr(0, sourcePath.length) != sourcePath) { | 486 if (sourceEntry.fullPath.substr(0, sourcePath.length) != sourcePath) { |
487 // We found an entry in the list that is not relative to the base source | 487 // We found an entry in the list that is not relative to the base source |
488 // path, something is wrong. | 488 // path, something is wrong. |
489 return onError('UNEXPECTED_SOURCE_FILE', sourceEntry.fullPath); | 489 return onError('UNEXPECTED_SOURCE_FILE', sourceEntry.fullPath); |
490 } | 490 } |
491 | 491 |
492 var targetDirEntry = task.targetDirEntry; | 492 var targetDirEntry = task.targetDirEntry; |
493 var originalPath = sourceEntry.fullPath.substr(sourcePath.length + 1); | 493 var originalPath = sourceEntry.fullPath.substr(sourcePath.length + 1); |
| 494 |
| 495 // If the source entry is GData search result, we should not use the file name |
| 496 // we get from file entry (this will be in format |
| 497 // resource_id.original_file_name). Instead, we should use original_file_name. |
| 498 // Note that if the entry is GData search result, it can only be immediate |
| 499 // child of |task.sourceDirEntry|, so originalPath should be equal to |
| 500 // gdataSearchResult.fileName. |
| 501 var gdataSearchResult = |
| 502 util.getFileAndDisplayNameForGDataSearchResult(sourceEntry.fullPath); |
| 503 if (gdataSearchResult && originalPath != gdataSearchResult.displayName) { |
| 504 if (sourceEntry.isDirectory) { |
| 505 // We usually register paths relative to sourceDirEntry, but since the |
| 506 // entries for which we have to do this can only be immediate children of |
| 507 // the source dir, registering names should be fine. |
| 508 task.registerRename(gdataSearchResult.fileName, |
| 509 gdataSearchResult.displayName); |
| 510 } |
| 511 // Registered rename paths are appended '/', so we have to change |
| 512 // |originalPath| for directory entries too. |originalPath| won't be changed |
| 513 // during applyRenames (at least not by applying just registered rename). |
| 514 originalPath = gdataSearchResult.displayName; |
| 515 } |
| 516 |
494 originalPath = task.applyRenames(originalPath); | 517 originalPath = task.applyRenames(originalPath); |
495 | 518 |
496 var targetRelativePrefix = originalPath; | 519 var targetRelativePrefix = originalPath; |
497 var targetExt = ''; | 520 var targetExt = ''; |
498 var index = targetRelativePrefix.lastIndexOf('.'); | 521 var index = targetRelativePrefix.lastIndexOf('.'); |
499 if (index != -1) { | 522 if (index != -1) { |
500 targetExt = targetRelativePrefix.substr(index); | 523 targetExt = targetRelativePrefix.substr(index); |
501 targetRelativePrefix = targetRelativePrefix.substr(0, index); | 524 targetRelativePrefix = targetRelativePrefix.substr(0, index); |
502 } | 525 } |
503 | 526 |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 successCallback(targetEntry, file.size); | 748 successCallback(targetEntry, file.size); |
726 }; | 749 }; |
727 writer.write(file); | 750 writer.write(file); |
728 } | 751 } |
729 | 752 |
730 targetEntry.createWriter(onWriterCreated, errorCallback); | 753 targetEntry.createWriter(onWriterCreated, errorCallback); |
731 } | 754 } |
732 | 755 |
733 sourceEntry.file(onSourceFileFound, errorCallback); | 756 sourceEntry.file(onSourceFileFound, errorCallback); |
734 }; | 757 }; |
OLD | NEW |