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

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

Issue 1882923003: Add best-effort/allow rollback flags on WorkItem. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@simple_list_tests
Patch Set: fix build error Created 4 years, 7 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) 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 "base/files/file_util.h" 5 #include "base/files/file_util.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "chrome/installer/util/create_dir_work_item.h" 7 #include "chrome/installer/util/create_dir_work_item.h"
8 #include "chrome/installer/util/logging_installer.h" 8 #include "chrome/installer/util/logging_installer.h"
9 9
10 CreateDirWorkItem::~CreateDirWorkItem() { 10 CreateDirWorkItem::~CreateDirWorkItem() {
(...skipping 11 matching lines...) Expand all
22 } 22 }
23 23
24 base::FilePath parent_dir(path_); 24 base::FilePath parent_dir(path_);
25 do { 25 do {
26 top_path_ = parent_dir; 26 top_path_ = parent_dir;
27 parent_dir = parent_dir.DirName(); 27 parent_dir = parent_dir.DirName();
28 } while ((parent_dir != top_path_) && !base::PathExists(parent_dir)); 28 } while ((parent_dir != top_path_) && !base::PathExists(parent_dir));
29 return; 29 return;
30 } 30 }
31 31
32 bool CreateDirWorkItem::Do() { 32 bool CreateDirWorkItem::DoImpl() {
33 VLOG(1) << "creating directory " << path_.value(); 33 VLOG(1) << "creating directory " << path_.value();
34 GetTopDirToCreate(); 34 GetTopDirToCreate();
35 if (top_path_.empty()) 35 if (top_path_.empty())
36 return true; 36 return true;
37 37
38 VLOG(1) << "top directory that needs to be created: " << top_path_.value(); 38 VLOG(1) << "top directory that needs to be created: " << top_path_.value();
39 bool result = base::CreateDirectory(path_); 39 bool result = base::CreateDirectory(path_);
40 VLOG(1) << "directory creation result: " << result; 40 VLOG(1) << "directory creation result: " << result;
41 41
42 rollback_needed_ = true; 42 rollback_needed_ = true;
43 43
44 return result; 44 return result;
45 } 45 }
46 46
47 void CreateDirWorkItem::Rollback() { 47 void CreateDirWorkItem::RollbackImpl() {
48 if (!rollback_needed_) 48 if (!rollback_needed_)
49 return; 49 return;
50 50
51 // Delete all the directories we created to rollback. 51 // Delete all the directories we created to rollback.
52 // Note we can not recusively delete top_path_ since we don't want to 52 // Note we can not recusively delete top_path_ since we don't want to
53 // delete non-empty directory. (We may have created a shared directory). 53 // delete non-empty directory. (We may have created a shared directory).
54 // Instead we walk through path_ to top_path_ and delete directories 54 // Instead we walk through path_ to top_path_ and delete directories
55 // along the way. 55 // along the way.
56 base::FilePath path_to_delete(path_); 56 base::FilePath path_to_delete(path_);
57 57
58 while (1) { 58 while (1) {
59 if (base::PathExists(path_to_delete)) { 59 if (base::PathExists(path_to_delete)) {
60 if (!RemoveDirectory(path_to_delete.value().c_str())) 60 if (!RemoveDirectory(path_to_delete.value().c_str()))
61 break; 61 break;
62 } 62 }
63 if (path_to_delete == top_path_) 63 if (path_to_delete == top_path_)
64 break; 64 break;
65 path_to_delete = path_to_delete.DirName(); 65 path_to_delete = path_to_delete.DirName();
66 } 66 }
67 67
68 return; 68 return;
69 } 69 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698