Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <io.h> | 8 #include <io.h> |
| 9 #include <psapi.h> | 9 #include <psapi.h> |
| 10 #include <shellapi.h> | 10 #include <shellapi.h> |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 if (real_to_path.empty()) | 170 if (real_to_path.empty()) |
| 171 return false; | 171 return false; |
| 172 } else { | 172 } else { |
| 173 real_to_path = MakeAbsoluteFilePath(real_to_path.DirName()); | 173 real_to_path = MakeAbsoluteFilePath(real_to_path.DirName()); |
| 174 if (real_to_path.empty()) | 174 if (real_to_path.empty()) |
| 175 return false; | 175 return false; |
| 176 } | 176 } |
| 177 FilePath real_from_path = MakeAbsoluteFilePath(from_path); | 177 FilePath real_from_path = MakeAbsoluteFilePath(from_path); |
| 178 if (real_from_path.empty()) | 178 if (real_from_path.empty()) |
| 179 return false; | 179 return false; |
| 180 | |
| 181 // Originally this CopyDirectory() returns false when |to_path| string | |
| 182 // contains |from_path| string. While this can be that the to_path is within | |
| 183 // the from_path, e.g., parent-child relationship if they are both folders, it | |
| 184 // also can be that the two paths are in the same folder, just that one name | |
| 185 // contains the other, e.g. C:\\JumpListIcon and C:\\JumpListIconOld. | |
| 186 // We make this function not return false in the latter situation by calling | |
| 187 // IsParent() function as below. This allows the copy-n-delete code after the | |
| 188 // "return false" beloe to execute. | |
| 180 if (real_to_path.value().size() >= real_from_path.value().size() && | 189 if (real_to_path.value().size() >= real_from_path.value().size() && |
|
brucedawson
2016/12/13 00:35:45
beloe -> below
Can you also add a comment explain
chengx
2016/12/13 01:40:16
I have fixed the typo, and added more comments to
| |
| 181 real_to_path.value().compare(0, real_from_path.value().size(), | 190 real_from_path.IsParent(real_to_path)) { |
| 182 real_from_path.value()) == 0) { | |
| 183 return false; | 191 return false; |
| 184 } | 192 } |
| 185 | 193 |
| 186 int traverse_type = FileEnumerator::FILES; | 194 int traverse_type = FileEnumerator::FILES; |
| 187 if (recursive) | 195 if (recursive) |
| 188 traverse_type |= FileEnumerator::DIRECTORIES; | 196 traverse_type |= FileEnumerator::DIRECTORIES; |
| 189 FileEnumerator traversal(from_path, recursive, traverse_type); | 197 FileEnumerator traversal(from_path, recursive, traverse_type); |
| 190 | 198 |
| 191 if (!PathExists(from_path)) { | 199 if (!PathExists(from_path)) { |
| 192 DLOG(ERROR) << "CopyDirectory() couldn't stat source directory: " | 200 DLOG(ERROR) << "CopyDirectory() couldn't stat source directory: " |
| (...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 823 // Like Move, this function is not transactional, so we just | 831 // Like Move, this function is not transactional, so we just |
| 824 // leave the copied bits behind if deleting from_path fails. | 832 // leave the copied bits behind if deleting from_path fails. |
| 825 // If to_path exists previously then we have already overwritten | 833 // If to_path exists previously then we have already overwritten |
| 826 // it by now, we don't get better off by deleting the new bits. | 834 // it by now, we don't get better off by deleting the new bits. |
| 827 } | 835 } |
| 828 return false; | 836 return false; |
| 829 } | 837 } |
| 830 | 838 |
| 831 } // namespace internal | 839 } // namespace internal |
| 832 } // namespace base | 840 } // namespace base |
| OLD | NEW |