OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/copy_tree_work_item.h" | 5 #include "chrome/installer/util/copy_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 11 matching lines...) Expand all Loading... |
22 dest_path_(dest_path), | 22 dest_path_(dest_path), |
23 temp_dir_(temp_dir), | 23 temp_dir_(temp_dir), |
24 overwrite_option_(overwrite_option), | 24 overwrite_option_(overwrite_option), |
25 alternative_path_(alternative_path), | 25 alternative_path_(alternative_path), |
26 copied_to_dest_path_(false), | 26 copied_to_dest_path_(false), |
27 moved_to_backup_(false), | 27 moved_to_backup_(false), |
28 copied_to_alternate_path_(false) { | 28 copied_to_alternate_path_(false) { |
29 } | 29 } |
30 | 30 |
31 bool CopyTreeWorkItem::Do() { | 31 bool CopyTreeWorkItem::Do() { |
32 if (!file_util::PathExists(source_path_)) { | 32 if (!base::PathExists(source_path_)) { |
33 LOG(ERROR) << source_path_.value() << " does not exist"; | 33 LOG(ERROR) << source_path_.value() << " does not exist"; |
34 return false; | 34 return false; |
35 } | 35 } |
36 | 36 |
37 bool dest_exist = file_util::PathExists(dest_path_); | 37 bool dest_exist = base::PathExists(dest_path_); |
38 // handle overwrite_option_ = IF_DIFFERENT case. | 38 // handle overwrite_option_ = IF_DIFFERENT case. |
39 if ((dest_exist) && | 39 if ((dest_exist) && |
40 (overwrite_option_ == WorkItem::IF_DIFFERENT) && // only for single file | 40 (overwrite_option_ == WorkItem::IF_DIFFERENT) && // only for single file |
41 (!file_util::DirectoryExists(source_path_)) && | 41 (!file_util::DirectoryExists(source_path_)) && |
42 (!file_util::DirectoryExists(dest_path_)) && | 42 (!file_util::DirectoryExists(dest_path_)) && |
43 (file_util::ContentsEqual(source_path_, dest_path_))) { | 43 (file_util::ContentsEqual(source_path_, dest_path_))) { |
44 VLOG(1) << "Source file " << source_path_.value() | 44 VLOG(1) << "Source file " << source_path_.value() |
45 << " and destination file " << dest_path_.value() | 45 << " and destination file " << dest_path_.value() |
46 << " are exactly same. Returning true."; | 46 << " are exactly same. Returning true."; |
47 return true; | 47 return true; |
48 } else if ((dest_exist) && | 48 } else if ((dest_exist) && |
49 (overwrite_option_ == WorkItem::NEW_NAME_IF_IN_USE) && | 49 (overwrite_option_ == WorkItem::NEW_NAME_IF_IN_USE) && |
50 (!file_util::DirectoryExists(source_path_)) && | 50 (!file_util::DirectoryExists(source_path_)) && |
51 (!file_util::DirectoryExists(dest_path_)) && | 51 (!file_util::DirectoryExists(dest_path_)) && |
52 (IsFileInUse(dest_path_))) { | 52 (IsFileInUse(dest_path_))) { |
53 // handle overwrite_option_ = NEW_NAME_IF_IN_USE case. | 53 // handle overwrite_option_ = NEW_NAME_IF_IN_USE case. |
54 if (alternative_path_.empty() || | 54 if (alternative_path_.empty() || |
55 file_util::PathExists(alternative_path_) || | 55 base::PathExists(alternative_path_) || |
56 !base::CopyFile(source_path_, alternative_path_)) { | 56 !base::CopyFile(source_path_, alternative_path_)) { |
57 LOG(ERROR) << "failed to copy " << source_path_.value() | 57 LOG(ERROR) << "failed to copy " << source_path_.value() |
58 << " to " << alternative_path_.value(); | 58 << " to " << alternative_path_.value(); |
59 return false; | 59 return false; |
60 } else { | 60 } else { |
61 copied_to_alternate_path_ = true; | 61 copied_to_alternate_path_ = true; |
62 VLOG(1) << "Copied source file " << source_path_.value() | 62 VLOG(1) << "Copied source file " << source_path_.value() |
63 << " to alternative path " << alternative_path_.value(); | 63 << " to alternative path " << alternative_path_.value(); |
64 return true; | 64 return true; |
65 } | 65 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 << " to " << dest_path_.value(); | 119 << " to " << dest_path_.value(); |
120 } | 120 } |
121 } | 121 } |
122 if (copied_to_alternate_path_ && | 122 if (copied_to_alternate_path_ && |
123 !base::Delete(alternative_path_, true)) { | 123 !base::Delete(alternative_path_, true)) { |
124 LOG(ERROR) << "Can not delete " << alternative_path_.value(); | 124 LOG(ERROR) << "Can not delete " << alternative_path_.value(); |
125 } | 125 } |
126 } | 126 } |
127 | 127 |
128 bool CopyTreeWorkItem::IsFileInUse(const base::FilePath& path) { | 128 bool CopyTreeWorkItem::IsFileInUse(const base::FilePath& path) { |
129 if (!file_util::PathExists(path)) | 129 if (!base::PathExists(path)) |
130 return false; | 130 return false; |
131 | 131 |
132 HANDLE handle = ::CreateFile(path.value().c_str(), FILE_ALL_ACCESS, | 132 HANDLE handle = ::CreateFile(path.value().c_str(), FILE_ALL_ACCESS, |
133 NULL, NULL, OPEN_EXISTING, NULL, NULL); | 133 NULL, NULL, OPEN_EXISTING, NULL, NULL); |
134 if (handle == INVALID_HANDLE_VALUE) | 134 if (handle == INVALID_HANDLE_VALUE) |
135 return true; | 135 return true; |
136 | 136 |
137 CloseHandle(handle); | 137 CloseHandle(handle); |
138 return false; | 138 return false; |
139 } | 139 } |
OLD | NEW |