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 #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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <windows.h> | |
10 | |
11 #include <string> | |
12 | |
13 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/gtest_prod_util.h" |
| 11 #include "base/scoped_temp_dir.h" |
14 #include "chrome/installer/util/work_item.h" | 12 #include "chrome/installer/util/work_item.h" |
15 | 13 |
16 // A WorkItem subclass that recursively copies a file system hierarchy from | 14 // A WorkItem subclass that recursively copies a file system hierarchy from |
17 // source path to destination path. It also creates all necessary intermediate | 15 // source path to destination path. It also creates all necessary intermediate |
18 // paths of the destination path if they do not exist. The file system | 16 // paths of the destination path if they do not exist. The file system |
19 // hierarchy could be a single file, or a directory. | 17 // hierarchy could be a single file, or a directory. |
20 // Under the cover CopyTreeWorkItem moves the destination path, if existing, | 18 // Under the cover CopyTreeWorkItem moves the destination path, if existing, |
21 // to the temporary directory passed in, and then copies the source hierarchy | 19 // to the temporary directory passed in, and then copies the source hierarchy |
22 // to the destination location. During rollback the original destination | 20 // to the destination location. During rollback the original destination |
23 // hierarchy is moved back. | 21 // hierarchy is moved back. |
(...skipping 15 matching lines...) Expand all Loading... |
39 // dest_path. | 37 // dest_path. |
40 CopyTreeWorkItem(const FilePath& source_path, | 38 CopyTreeWorkItem(const FilePath& source_path, |
41 const FilePath& dest_path, | 39 const FilePath& dest_path, |
42 const FilePath& temp_dir, | 40 const FilePath& temp_dir, |
43 CopyOverWriteOption overwrite_option, | 41 CopyOverWriteOption overwrite_option, |
44 const FilePath& alternative_path); | 42 const FilePath& alternative_path); |
45 | 43 |
46 // Checks if the path specified is in use (and hence can not be deleted) | 44 // Checks if the path specified is in use (and hence can not be deleted) |
47 bool IsFileInUse(const FilePath& path); | 45 bool IsFileInUse(const FilePath& path); |
48 | 46 |
49 // Get a backup path that can keep the original files under dest_path_, | |
50 // and set backup_path_ with the result. | |
51 bool GetBackupPath(); | |
52 | |
53 // Source path to copy files from. | 47 // Source path to copy files from. |
54 FilePath source_path_; | 48 FilePath source_path_; |
55 | 49 |
56 // Destination path to copy files to. | 50 // Destination path to copy files to. |
57 FilePath dest_path_; | 51 FilePath dest_path_; |
58 | 52 |
59 // Temporary directory that can be used. | 53 // Temporary directory that can be used. |
60 FilePath temp_dir_; | 54 FilePath temp_dir_; |
61 | 55 |
62 // Controls the behavior for overwriting. | 56 // Controls the behavior for overwriting. |
63 CopyOverWriteOption overwrite_option_; | 57 CopyOverWriteOption overwrite_option_; |
64 | 58 |
65 // If overwrite_option_ = NEW_NAME_IF_IN_USE, this variables stores the path | 59 // If overwrite_option_ = NEW_NAME_IF_IN_USE, this variables stores the path |
66 // to be used if the file is in use and hence we want to copy it to a | 60 // to be used if the file is in use and hence we want to copy it to a |
67 // different path. | 61 // different path. |
68 FilePath alternative_path_; | 62 FilePath alternative_path_; |
69 | 63 |
70 // Whether the source was copied to dest_path_ | 64 // Whether the source was copied to dest_path_ |
71 bool copied_to_dest_path_; | 65 bool copied_to_dest_path_; |
72 | 66 |
73 // Whether the original files have been moved to backup path under | 67 // Whether the original files have been moved to backup path under |
74 // temporary directory. If true, moving back is needed during rollback. | 68 // temporary directory. If true, moving back is needed during rollback. |
75 bool moved_to_backup_; | 69 bool moved_to_backup_; |
76 | 70 |
77 // Whether the source was copied to alternative_path_ because dest_path_ | 71 // Whether the source was copied to alternative_path_ because dest_path_ |
78 // existed and was in use. Needed during rollback. | 72 // existed and was in use. Needed during rollback. |
79 bool copied_to_alternate_path_; | 73 bool copied_to_alternate_path_; |
80 | 74 |
81 // The full path in temporary directory that the original dest_path_ has | 75 // The temporary directory into which the original dest_path_ has been moved. |
82 // been moved to. | 76 ScopedTempDir backup_path_; |
83 FilePath backup_path_; | 77 |
| 78 FRIEND_TEST_ALL_PREFIXES(CopyTreeWorkItemTest, CopyFileSameContent); |
| 79 FRIEND_TEST_ALL_PREFIXES(CopyTreeWorkItemTest, CopyFileInUse); |
| 80 FRIEND_TEST_ALL_PREFIXES(CopyTreeWorkItemTest, CopyFileAndCleanup); |
| 81 FRIEND_TEST_ALL_PREFIXES(CopyTreeWorkItemTest, NewNameAndCopyTest); |
| 82 FRIEND_TEST_ALL_PREFIXES(CopyTreeWorkItemTest, CopyFileInUseAndCleanup); |
84 }; | 83 }; |
85 | 84 |
86 #endif // CHROME_INSTALLER_UTIL_COPY_TREE_WORK_ITEM_H_ | 85 #endif // CHROME_INSTALLER_UTIL_COPY_TREE_WORK_ITEM_H_ |
OLD | NEW |