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

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

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) 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 #ifndef CHROME_INSTALLER_UTIL_COPY_TREE_WORK_ITEM_H_ 5 #ifndef CHROME_INSTALLER_UTIL_COPY_TREE_WORK_ITEM_H_
6 #define CHROME_INSTALLER_UTIL_COPY_TREE_WORK_ITEM_H_ 6 #define CHROME_INSTALLER_UTIL_COPY_TREE_WORK_ITEM_H_
7 7
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/gtest_prod_util.h" 10 #include "base/gtest_prod_util.h"
11 #include "chrome/installer/util/work_item.h" 11 #include "chrome/installer/util/work_item.h"
12 12
13 // A WorkItem subclass that recursively copies a file system hierarchy from 13 // A WorkItem subclass that recursively copies a file system hierarchy from
14 // source path to destination path. It also creates all necessary intermediate 14 // source path to destination path. It also creates all necessary intermediate
15 // paths of the destination path if they do not exist. The file system 15 // paths of the destination path if they do not exist. The file system
16 // hierarchy could be a single file, or a directory. 16 // hierarchy could be a single file, or a directory.
17 // Under the cover CopyTreeWorkItem moves the destination path, if existing, 17 // Under the cover CopyTreeWorkItem moves the destination path, if existing,
18 // to the temporary directory passed in, and then copies the source hierarchy 18 // to the temporary directory passed in, and then copies the source hierarchy
19 // to the destination location. During rollback the original destination 19 // to the destination location. During rollback the original destination
20 // hierarchy is moved back. 20 // hierarchy is moved back.
21 // NOTE: It is a best practice to ensure that the temporary directory is on the 21 // NOTE: It is a best practice to ensure that the temporary directory is on the
22 // same volume as the destination path. If this is not the case, the existing 22 // same volume as the destination path. If this is not the case, the existing
23 // destination path is not moved, but rather copied, to the destination path. 23 // destination path is not moved, but rather copied, to the destination path.
24 // This will result in in-use files being left behind, as well as potentially 24 // This will result in in-use files being left behind, as well as potentially
25 // losing ACLs or other metadata in the case of a rollback. 25 // losing ACLs or other metadata in the case of a rollback.
26 class CopyTreeWorkItem : public WorkItem { 26 class CopyTreeWorkItem : public WorkItem {
27 public: 27 public:
28 ~CopyTreeWorkItem() override; 28 ~CopyTreeWorkItem() override;
29 29
30 bool Do() override;
31
32 void Rollback() override;
33
34 private: 30 private:
35 friend class WorkItem; 31 friend class WorkItem;
36 32
37 // See comments on corresponding member variables for the semantics of 33 // See comments on corresponding member variables for the semantics of
38 // arguments. 34 // arguments.
39 // Notes on temp_path: to facilitate rollback, the caller needs to supply 35 // Notes on temp_path: to facilitate rollback, the caller needs to supply
40 // a temporary directory to save the original files if they exist under 36 // a temporary directory to save the original files if they exist under
41 // dest_path. 37 // dest_path.
42 CopyTreeWorkItem(const base::FilePath& source_path, 38 CopyTreeWorkItem(const base::FilePath& source_path,
43 const base::FilePath& dest_path, 39 const base::FilePath& dest_path,
44 const base::FilePath& temp_dir, 40 const base::FilePath& temp_dir,
45 CopyOverWriteOption overwrite_option, 41 CopyOverWriteOption overwrite_option,
46 const base::FilePath& alternative_path); 42 const base::FilePath& alternative_path);
47 43
44 // WorkItem:
45 bool DoImpl() override;
46 void RollbackImpl() override;
47
48 // Checks if the path specified is in use (and hence can not be deleted) 48 // Checks if the path specified is in use (and hence can not be deleted)
49 bool IsFileInUse(const base::FilePath& path); 49 bool IsFileInUse(const base::FilePath& path);
50 50
51 // Source path to copy files from. 51 // Source path to copy files from.
52 base::FilePath source_path_; 52 base::FilePath source_path_;
53 53
54 // Destination path to copy files to. 54 // Destination path to copy files to.
55 base::FilePath dest_path_; 55 base::FilePath dest_path_;
56 56
57 // Temporary directory that can be used. 57 // Temporary directory that can be used.
(...skipping 22 matching lines...) Expand all
80 base::ScopedTempDir backup_path_; 80 base::ScopedTempDir backup_path_;
81 81
82 FRIEND_TEST_ALL_PREFIXES(CopyTreeWorkItemTest, CopyFileSameContent); 82 FRIEND_TEST_ALL_PREFIXES(CopyTreeWorkItemTest, CopyFileSameContent);
83 FRIEND_TEST_ALL_PREFIXES(CopyTreeWorkItemTest, CopyFileInUse); 83 FRIEND_TEST_ALL_PREFIXES(CopyTreeWorkItemTest, CopyFileInUse);
84 FRIEND_TEST_ALL_PREFIXES(CopyTreeWorkItemTest, CopyFileAndCleanup); 84 FRIEND_TEST_ALL_PREFIXES(CopyTreeWorkItemTest, CopyFileAndCleanup);
85 FRIEND_TEST_ALL_PREFIXES(CopyTreeWorkItemTest, NewNameAndCopyTest); 85 FRIEND_TEST_ALL_PREFIXES(CopyTreeWorkItemTest, NewNameAndCopyTest);
86 FRIEND_TEST_ALL_PREFIXES(CopyTreeWorkItemTest, CopyFileInUseAndCleanup); 86 FRIEND_TEST_ALL_PREFIXES(CopyTreeWorkItemTest, CopyFileInUseAndCleanup);
87 }; 87 };
88 88
89 #endif // CHROME_INSTALLER_UTIL_COPY_TREE_WORK_ITEM_H_ 89 #endif // CHROME_INSTALLER_UTIL_COPY_TREE_WORK_ITEM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698