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

Side by Side Diff: chrome/installer/util/copy_tree_work_item.cc

Issue 151101: Fixit: Remove bunch of coverity warnings from chrome/installer/*. (Closed)
Patch Set: Created 11 years, 5 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
OLDNEW
1 // Copyright (c) 2006-2008 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/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 #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
11 CopyTreeWorkItem::~CopyTreeWorkItem() { 11 CopyTreeWorkItem::~CopyTreeWorkItem() {
12 if (file_util::PathExists(backup_path_)) { 12 if (file_util::PathExists(backup_path_)) {
13 file_util::Delete(backup_path_, true); 13 file_util::Delete(backup_path_, true);
14 } 14 }
15 } 15 }
16 16
17 CopyTreeWorkItem::CopyTreeWorkItem(std::wstring source_path, 17 CopyTreeWorkItem::CopyTreeWorkItem(const std::wstring& source_path,
18 std::wstring dest_path, 18 const std::wstring& dest_path,
19 std::wstring temp_dir, 19 const std::wstring& temp_dir,
20 CopyOverWriteOption overwrite_option, 20 CopyOverWriteOption overwrite_option,
21 std::wstring alternative_path) 21 const std::wstring& alternative_path)
22 : source_path_(source_path), 22 : source_path_(source_path),
23 dest_path_(dest_path), 23 dest_path_(dest_path),
24 temp_dir_(temp_dir), 24 temp_dir_(temp_dir),
25 overwrite_option_(overwrite_option), 25 overwrite_option_(overwrite_option),
26 alternative_path_(alternative_path), 26 alternative_path_(alternative_path),
27 copied_to_dest_path_(false), 27 copied_to_dest_path_(false),
28 moved_to_backup_(false), 28 moved_to_backup_(false),
29 copied_to_alternate_path_(false) { 29 copied_to_alternate_path_(false) {
30 } 30 }
31 31
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 } 109 }
110 if (moved_to_backup_ && !file_util::Move(backup_path_, dest_path_)) { 110 if (moved_to_backup_ && !file_util::Move(backup_path_, dest_path_)) {
111 LOG(ERROR) << "failed move " << backup_path_ << " to " << dest_path_; 111 LOG(ERROR) << "failed move " << backup_path_ << " to " << dest_path_;
112 } 112 }
113 if (copied_to_alternate_path_ && 113 if (copied_to_alternate_path_ &&
114 !file_util::Delete(alternative_path_, true)) { 114 !file_util::Delete(alternative_path_, true)) {
115 LOG(ERROR) << "Can not delete " << alternative_path_; 115 LOG(ERROR) << "Can not delete " << alternative_path_;
116 } 116 }
117 } 117 }
118 118
119 bool CopyTreeWorkItem::IsFileInUse(std::wstring path) { 119 bool CopyTreeWorkItem::IsFileInUse(const std::wstring& path) {
120 if (!file_util::PathExists(path)) 120 if (!file_util::PathExists(path))
121 return false; 121 return false;
122 122
123 HANDLE handle = ::CreateFile(path.c_str(), FILE_ALL_ACCESS, 123 HANDLE handle = ::CreateFile(path.c_str(), FILE_ALL_ACCESS,
124 NULL, NULL, OPEN_EXISTING, NULL, NULL); 124 NULL, NULL, OPEN_EXISTING, NULL, NULL);
125 if (handle == INVALID_HANDLE_VALUE) 125 if (handle == INVALID_HANDLE_VALUE)
126 return true; 126 return true;
127 127
128 CloseHandle(handle); 128 CloseHandle(handle);
129 return false; 129 return false;
130 } 130 }
131 131
132 bool CopyTreeWorkItem::GetBackupPath() { 132 bool CopyTreeWorkItem::GetBackupPath() {
133 std::wstring file_name = file_util::GetFilenameFromPath(dest_path_); 133 std::wstring file_name = file_util::GetFilenameFromPath(dest_path_);
134 backup_path_.assign(temp_dir_); 134 backup_path_.assign(temp_dir_);
135 file_util::AppendToPath(&backup_path_, file_name); 135 file_util::AppendToPath(&backup_path_, file_name);
136 136
137 if (file_util::PathExists(backup_path_)) { 137 if (file_util::PathExists(backup_path_)) {
138 // Ideally we should not fail immediately. Instead we could try some 138 // Ideally we should not fail immediately. Instead we could try some
139 // random paths under temp_dir_ until we reach certain limit. 139 // random paths under temp_dir_ until we reach certain limit.
140 // For now our caller always provides a good temporary directory so 140 // For now our caller always provides a good temporary directory so
141 // we don't bother. 141 // we don't bother.
142 LOG(ERROR) << "backup path " << backup_path_ << " already exists"; 142 LOG(ERROR) << "backup path " << backup_path_ << " already exists";
143 return false; 143 return false;
144 } 144 }
145 145
146 return true; 146 return true;
147 } 147 }
OLDNEW
« no previous file with comments | « chrome/installer/util/copy_tree_work_item.h ('k') | chrome/installer/util/copy_tree_work_item_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698