Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Side by Side Diff: chrome/browser/resources/file_manager/js/file_copy_manager.js

Issue 9694057: Fix arguments passed to FileEntry.copyTo() and FileEntry.moveTo(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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() { 5 function FileCopyManager() {
6 this.copyTasks_ = []; 6 this.copyTasks_ = [];
7 this.cancelObservers_ = []; 7 this.cancelObservers_ = [];
8 this.cancelRequested_ = false; 8 this.cancelRequested_ = false;
9 } 9 }
10 10
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 function onCopyComplete(entry, size) { 441 function onCopyComplete(entry, size) {
442 task.markEntryComplete(entry, size); 442 task.markEntryComplete(entry, size);
443 successCallback(entry, size); 443 successCallback(entry, size);
444 } 444 }
445 445
446 function onError(reason, data) { 446 function onError(reason, data) {
447 console.log('serviceNextTaskEntry error: ' + reason + ':', data); 447 console.log('serviceNextTaskEntry error: ' + reason + ':', data);
448 errorCallback(new FileCopyManager.Error(reason, data)); 448 errorCallback(new FileCopyManager.Error(reason, data));
449 } 449 }
450 450
451 function onFilesystemCopyComplete(entry) {
452 // TODO(benchan): We currently do not know the size of data being
453 // copied by FileEntry.copyTo(), so task.completedBytes will not be
454 // increased. We will address this issue once we need to use
455 // task.completedBytes to track the progress.
456 onCopyComplete(entry, 0);
457 }
458
451 function onFilesystemError(err) { 459 function onFilesystemError(err) {
452 onError('FILESYSTEM_ERROR', err); 460 onError('FILESYSTEM_ERROR', err);
453 } 461 }
454 462
455 function onTargetExists(existingEntry) { 463 function onTargetExists(existingEntry) {
456 if (!firstExistingEntry) 464 if (!firstExistingEntry)
457 firstExistingEntry = existingEntry; 465 firstExistingEntry = existingEntry;
458 renameTries++; 466 renameTries++;
459 if (renameTries < 10) { 467 if (renameTries < 10) {
460 copyNumber++; 468 copyNumber++;
461 tryNextCopy(); 469 tryNextCopy();
462 } else { 470 } else {
463 onError('TARGET_EXISTS', firstExistingEntry); 471 onError('TARGET_EXISTS', firstExistingEntry);
464 } 472 }
465 } 473 }
466 474
475 /**
476 * Resolves the immediate parent directory entry and the file name of a
477 * given path, where the path is specified by a directory (not necessarily
478 * the immediate parent) and a path (not necessarily the file name) related
479 * to that directory. For instance,
480 * Given:
481 * |dirEntry| = DirectoryEntry('/root/dir1')
482 * |relativePath| = 'dir2/file'
483 *
484 * Return:
485 * |parentDirEntry| = DirectoryEntry('/root/dir1/dir2')
486 * |fileName| = 'file'
487 *
488 * @param {DirectoryEntry} dirEntry A directory entry.
489 * @param {string} relativePath A path relative to |dirEntry|.
490 * @param {function(Entry,string)} A callback for returning the
491 * |parentDirEntry| and |fileName| upon success.
492 * @param {function(FileError)} An error callback when there is an error
493 * getting |parentDirEntry|.
494 */
495 function resolveDirAndBaseName(dirEntry, relativePath,
496 successCallback, errorCallback) {
497 // |intermediatePath| contains the intermediate path components
498 // that are appended to |dirEntry| to form |parentDirEntry|.
499 var intermediatePath = '';
500 var fileName = relativePath;
501
502 // Extract the file name component from |relativePath|.
503 var index = relativePath.lastIndexOf('/');
504 if (index != -1) {
505 intermediatePath = relativePath.substr(0, index);
506 fileName = relativePath.substr(index + 1);
507 }
508
509 if (intermediatePath == '') {
510 successCallback(dirEntry, fileName);
511 } else {
512 dirEntry.getDirectory(intermediatePath,
513 {create: false},
514 function(entry) {
515 successCallback(entry, fileName);
516 },
517 errorCallback);
518 }
519 }
520
467 function onTargetNotResolved(err) { 521 function onTargetNotResolved(err) {
468 // We expect to be unable to resolve the target file, since we're going 522 // We expect to be unable to resolve the target file, since we're going
469 // to create it during the copy. However, if the resolve fails with 523 // to create it during the copy. However, if the resolve fails with
470 // anything other than NOT_FOUND, that's trouble. 524 // anything other than NOT_FOUND, that's trouble.
471 if (err.code != FileError.NOT_FOUND_ERR) 525 if (err.code != FileError.NOT_FOUND_ERR)
472 return onError('FILESYSTEM_ERROR', err); 526 return onError('FILESYSTEM_ERROR', err);
473 527
474 if (task.sourceAndTargetOnGData) { 528 if (task.sourceAndTargetOnGData) {
475 if (task.deleteAfterCopy) { 529 if (task.deleteAfterCopy) {
476 sourceEntry.moveTo(targetDirEntry, targetRelativePath, 530 resolveDirAndBaseName(
477 onCopyComplete, onError); 531 targetDirEntry, targetRelativePath,
532 function(dirEntry, fileName) {
533 sourceEntry.moveTo(dirEntry, fileName,
534 onFilesystemCopyComplete, onFilesystemError);
535 },
536 onFilesystemError);
478 return; 537 return;
479 } else { 538 } else {
480 // TODO(benchan): GDataFileSystem has not implemented directory copy, 539 // TODO(benchan): GDataFileSystem has not implemented directory copy,
481 // and thus we only call FileEntry.copyTo() for files. Revisit this 540 // and thus we only call FileEntry.copyTo() for files. Revisit this
482 // code when GDataFileSystem supports directory copy. 541 // code when GDataFileSystem supports directory copy.
483 if (!sourceEntry.isDirectory) { 542 if (!sourceEntry.isDirectory) {
484 sourceEntry.copyTo(targetDirEntry, targetRelativePath, 543 resolveDirAndBaseName(
485 onCopyComplete, onError); 544 targetDirEntry, targetRelativePath,
545 function(dirEntry, fileName) {
546 sourceEntry.copyTo(dirEntry, fileName,
547 onFilesystemCopyComplete, onFilesystemError);
548 },
549 onFilesystemError);
486 return; 550 return;
487 } 551 }
488 } 552 }
489 } 553 }
490 554
491 if (sourceEntry.isDirectory) { 555 if (sourceEntry.isDirectory) {
492 targetDirEntry.getDirectory( 556 targetDirEntry.getDirectory(
493 targetRelativePath, 557 targetRelativePath,
494 {create: true, exclusive: true}, 558 {create: true, exclusive: true},
495 function(targetEntry) { 559 function(targetEntry) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 successCallback(targetEntry, file.size) 610 successCallback(targetEntry, file.size)
547 }; 611 };
548 writer.write(file); 612 writer.write(file);
549 } 613 }
550 614
551 targetEntry.createWriter(onWriterCreated, errorCallback); 615 targetEntry.createWriter(onWriterCreated, errorCallback);
552 } 616 }
553 617
554 sourceEntry.file(onSourceFileFound, errorCallback); 618 sourceEntry.file(onSourceFileFound, errorCallback);
555 }; 619 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698