| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "chrome/installer/util/logging_installer.h" | 9 #include "chrome/installer/util/logging_installer.h" |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 moved_to_dest_path_(false), | 23 moved_to_dest_path_(false), |
| 24 moved_to_backup_(false) { | 24 moved_to_backup_(false) { |
| 25 } | 25 } |
| 26 | 26 |
| 27 bool MoveTreeWorkItem::Do() { | 27 bool MoveTreeWorkItem::Do() { |
| 28 if (!file_util::PathExists(source_path_)) { | 28 if (!file_util::PathExists(source_path_)) { |
| 29 LOG(ERROR) << source_path_ << " does not exist"; | 29 LOG(ERROR) << source_path_ << " does not exist"; |
| 30 return false; | 30 return false; |
| 31 } | 31 } |
| 32 | 32 |
| 33 FilePath backup_path; |
| 34 |
| 33 // If dest_path_ exists, move destination to a backup path. | 35 // If dest_path_ exists, move destination to a backup path. |
| 34 if (file_util::PathExists(dest_path_)) { | 36 if (file_util::PathExists(dest_path_)) { |
| 35 // Generate a backup path that can keep the original files under dest_path_. | 37 // Generate a backup path that can keep the original files under dest_path_. |
| 36 if (!file_util::CreateTemporaryFileNameInDir(temp_dir_, &backup_path_)) { | 38 if (!file_util::CreateTemporaryFileInDir(FilePath(temp_dir_), |
| 39 &backup_path)) { |
| 37 LOG(ERROR) << "Failed to get backup path in folder " << temp_dir_; | 40 LOG(ERROR) << "Failed to get backup path in folder " << temp_dir_; |
| 38 return false; | 41 return false; |
| 39 } | 42 } |
| 40 | 43 |
| 44 backup_path_ = backup_path.value(); |
| 45 |
| 41 if (file_util::Move(dest_path_, backup_path_)) { | 46 if (file_util::Move(dest_path_, backup_path_)) { |
| 42 moved_to_backup_ = true; | 47 moved_to_backup_ = true; |
| 43 LOG(INFO) << "Moved destination " << dest_path_ | 48 LOG(INFO) << "Moved destination " << dest_path_ |
| 44 << " to backup path " << backup_path_; | 49 << " to backup path " << backup_path_; |
| 45 } else { | 50 } else { |
| 46 LOG(ERROR) << "failed moving " << dest_path_ << " to " << backup_path_; | 51 LOG(ERROR) << "failed moving " << dest_path_ |
| 52 << " to " << backup_path_; |
| 47 return false; | 53 return false; |
| 48 } | 54 } |
| 49 } | 55 } |
| 50 | 56 |
| 51 // Now move source to destination. | 57 // Now move source to destination. |
| 52 if (file_util::Move(source_path_, dest_path_)) { | 58 if (file_util::Move(source_path_, dest_path_)) { |
| 53 moved_to_dest_path_ = true; | 59 moved_to_dest_path_ = true; |
| 54 LOG(INFO) << "Moved source " << source_path_ | 60 LOG(INFO) << "Moved source " << source_path_ |
| 55 << " to destination " << dest_path_; | 61 << " to destination " << dest_path_; |
| 56 } else { | 62 } else { |
| 57 LOG(ERROR) << "failed move " << source_path_ << " to " << dest_path_; | 63 LOG(ERROR) << "failed move " << source_path_ << " to " << dest_path_; |
| 58 return false; | 64 return false; |
| 59 } | 65 } |
| 60 | 66 |
| 61 return true; | 67 return true; |
| 62 } | 68 } |
| 63 | 69 |
| 64 void MoveTreeWorkItem::Rollback() { | 70 void MoveTreeWorkItem::Rollback() { |
| 65 if (moved_to_dest_path_ && !file_util::Move(dest_path_, source_path_)) | 71 if (moved_to_dest_path_ && !file_util::Move(dest_path_, source_path_)) |
| 66 LOG(ERROR) << "Can not move " << dest_path_ << " to " << source_path_; | 72 LOG(ERROR) << "Can not move " << dest_path_ << " to " << source_path_; |
| 67 | 73 |
| 68 if (moved_to_backup_ && !file_util::Move(backup_path_, dest_path_)) | 74 if (moved_to_backup_ && !file_util::Move(backup_path_, dest_path_)) |
| 69 LOG(ERROR) << "failed move " << backup_path_ << " to " << dest_path_; | 75 LOG(ERROR) << "failed move " << backup_path_ << " to " << dest_path_; |
| 70 } | 76 } |
| OLD | NEW |