| 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 #include "chrome/browser/chromeos/drive/file_cache.h" | 5 #include "chrome/browser/chromeos/drive/file_cache.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 const base::FilePath& dest_path) { | 83 const base::FilePath& dest_path) { |
| 84 if (!base::Move(source_path, dest_path)) { | 84 if (!base::Move(source_path, dest_path)) { |
| 85 LOG(ERROR) << "Failed to move " << source_path.value() | 85 LOG(ERROR) << "Failed to move " << source_path.value() |
| 86 << " to " << dest_path.value(); | 86 << " to " << dest_path.value(); |
| 87 return false; | 87 return false; |
| 88 } | 88 } |
| 89 DVLOG(1) << "Moved " << source_path.value() << " to " << dest_path.value(); | 89 DVLOG(1) << "Moved " << source_path.value() << " to " << dest_path.value(); |
| 90 return true; | 90 return true; |
| 91 } | 91 } |
| 92 | 92 |
| 93 // Copies the file. | 93 // Copies the file. Note this isn't called CopyFile which collides with |
| 94 bool CopyFile(const base::FilePath& source_path, | 94 // base::CopyFile when doing argument-dependent name lookup. |
| 95 const base::FilePath& dest_path) { | 95 bool CopyFileWrapper(const base::FilePath& source_path, |
| 96 if (!file_util::CopyFile(source_path, dest_path)) { | 96 const base::FilePath& dest_path) { |
| 97 if (!base::CopyFile(source_path, dest_path)) { |
| 97 LOG(ERROR) << "Failed to copy " << source_path.value() | 98 LOG(ERROR) << "Failed to copy " << source_path.value() |
| 98 << " to " << dest_path.value(); | 99 << " to " << dest_path.value(); |
| 99 return false; | 100 return false; |
| 100 } | 101 } |
| 101 DVLOG(1) << "Copied " << source_path.value() << " to " << dest_path.value(); | 102 DVLOG(1) << "Copied " << source_path.value() << " to " << dest_path.value(); |
| 102 return true; | 103 return true; |
| 103 } | 104 } |
| 104 | 105 |
| 105 // Deletes all files that match |path_to_delete_pattern| except for | 106 // Deletes all files that match |path_to_delete_pattern| except for |
| 106 // |path_to_keep| on blocking pool. | 107 // |path_to_keep| on blocking pool. |
| (...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 return FILE_ERROR_IN_USE; | 676 return FILE_ERROR_IN_USE; |
| 676 | 677 |
| 677 base::FilePath dest_path = GetCacheFilePath(resource_id, md5, | 678 base::FilePath dest_path = GetCacheFilePath(resource_id, md5, |
| 678 CACHED_FILE_FROM_SERVER); | 679 CACHED_FILE_FROM_SERVER); |
| 679 bool success = false; | 680 bool success = false; |
| 680 switch (file_operation_type) { | 681 switch (file_operation_type) { |
| 681 case FILE_OPERATION_MOVE: | 682 case FILE_OPERATION_MOVE: |
| 682 success = MoveFile(source_path, dest_path); | 683 success = MoveFile(source_path, dest_path); |
| 683 break; | 684 break; |
| 684 case FILE_OPERATION_COPY: | 685 case FILE_OPERATION_COPY: |
| 685 success = CopyFile(source_path, dest_path); | 686 success = CopyFileWrapper(source_path, dest_path); |
| 686 break; | 687 break; |
| 687 default: | 688 default: |
| 688 NOTREACHED(); | 689 NOTREACHED(); |
| 689 } | 690 } |
| 690 | 691 |
| 691 // Determine search pattern for stale filenames corresponding to resource_id, | 692 // Determine search pattern for stale filenames corresponding to resource_id, |
| 692 // either "<resource_id>*" or "<resource_id>.*". | 693 // either "<resource_id>*" or "<resource_id>.*". |
| 693 base::FilePath stale_filenames_pattern; | 694 base::FilePath stale_filenames_pattern; |
| 694 if (md5.empty()) { | 695 if (md5.empty()) { |
| 695 // No md5 means no extension, append '*' after base name, i.e. | 696 // No md5 means no extension, append '*' after base name, i.e. |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 } | 831 } |
| 831 } | 832 } |
| 832 | 833 |
| 833 // Delete old DB. | 834 // Delete old DB. |
| 834 base::Delete(old_db_path, true /* recursive */ ); | 835 base::Delete(old_db_path, true /* recursive */ ); |
| 835 return imported; | 836 return imported; |
| 836 } | 837 } |
| 837 | 838 |
| 838 } // namespace internal | 839 } // namespace internal |
| 839 } // namespace drive | 840 } // namespace drive |
| OLD | NEW |