| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/installer/util/move_tree_work_item.h" | 5 #include "chrome/installer/util/move_tree_work_item.h" |
| 6 | 6 |
| 7 #include <shlwapi.h> | 7 #include <shlwapi.h> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 : source_path_(source_path), | 21 : source_path_(source_path), |
| 22 dest_path_(dest_path), | 22 dest_path_(dest_path), |
| 23 temp_dir_(temp_dir), | 23 temp_dir_(temp_dir), |
| 24 duplicate_option_(duplicate_option), | 24 duplicate_option_(duplicate_option), |
| 25 moved_to_dest_path_(false), | 25 moved_to_dest_path_(false), |
| 26 moved_to_backup_(false), | 26 moved_to_backup_(false), |
| 27 source_moved_to_backup_(false) { | 27 source_moved_to_backup_(false) { |
| 28 } | 28 } |
| 29 | 29 |
| 30 bool MoveTreeWorkItem::Do() { | 30 bool MoveTreeWorkItem::Do() { |
| 31 if (!file_util::PathExists(source_path_)) { | 31 if (!base::PathExists(source_path_)) { |
| 32 LOG(ERROR) << source_path_.value() << " does not exist"; | 32 LOG(ERROR) << source_path_.value() << " does not exist"; |
| 33 return false; | 33 return false; |
| 34 } | 34 } |
| 35 | 35 |
| 36 // If dest_path_ exists, we can do one of two things: | 36 // If dest_path_ exists, we can do one of two things: |
| 37 // 1) If the contents of src_path_are already fully contained in dest_path_ | 37 // 1) If the contents of src_path_are already fully contained in dest_path_ |
| 38 // then do nothing and return success. Fully contained means the full | 38 // then do nothing and return success. Fully contained means the full |
| 39 // file structure with identical files is contained in dest_path_. For | 39 // file structure with identical files is contained in dest_path_. For |
| 40 // Chrome, if dest_path_ exists, this is expected to be the common case. | 40 // Chrome, if dest_path_ exists, this is expected to be the common case. |
| 41 // 2) If the contents of src_path_ are NOT fully contained in dest_path_, we | 41 // 2) If the contents of src_path_ are NOT fully contained in dest_path_, we |
| 42 // attempt to backup dest_path_ and replace it with src_path_. This will | 42 // attempt to backup dest_path_ and replace it with src_path_. This will |
| 43 // fail if files in dest_path_ are in use. | 43 // fail if files in dest_path_ are in use. |
| 44 if (file_util::PathExists(dest_path_)) { | 44 if (base::PathExists(dest_path_)) { |
| 45 // Generate a backup path that can keep the original files under dest_path_. | 45 // Generate a backup path that can keep the original files under dest_path_. |
| 46 if (!backup_path_.CreateUniqueTempDirUnderPath(temp_dir_)) { | 46 if (!backup_path_.CreateUniqueTempDirUnderPath(temp_dir_)) { |
| 47 PLOG(ERROR) << "Failed to get backup path in folder " | 47 PLOG(ERROR) << "Failed to get backup path in folder " |
| 48 << temp_dir_.value(); | 48 << temp_dir_.value(); |
| 49 return false; | 49 return false; |
| 50 } | 50 } |
| 51 base::FilePath backup = backup_path_.path().Append(dest_path_.BaseName()); | 51 base::FilePath backup = backup_path_.path().Append(dest_path_.BaseName()); |
| 52 | 52 |
| 53 if (duplicate_option_ == CHECK_DUPLICATES) { | 53 if (duplicate_option_ == CHECK_DUPLICATES) { |
| 54 if (installer::IsIdenticalFileHierarchy(source_path_, dest_path_)) { | 54 if (installer::IsIdenticalFileHierarchy(source_path_, dest_path_)) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 if (moved_to_backup_ && !base::Move(backup, dest_path_)) { | 108 if (moved_to_backup_ && !base::Move(backup, dest_path_)) { |
| 109 LOG(ERROR) << "failed move " << backup.value() | 109 LOG(ERROR) << "failed move " << backup.value() |
| 110 << " to " << dest_path_.value(); | 110 << " to " << dest_path_.value(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 if (source_moved_to_backup_ && !base::Move(backup, source_path_)) { | 113 if (source_moved_to_backup_ && !base::Move(backup, source_path_)) { |
| 114 LOG(ERROR) << "Can not restore " << backup.value() | 114 LOG(ERROR) << "Can not restore " << backup.value() |
| 115 << " to " << source_path_.value(); | 115 << " to " << source_path_.value(); |
| 116 } | 116 } |
| 117 } | 117 } |
| OLD | NEW |