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 // Note: it's important to use IsParent() here as string comparison would | 180 if (real_to_path == real_from_path || real_from_path.IsParent(real_to_path)) |
181 // result in a false negative, e.g. on C:\bar\Foo versus C:\bar\FooOld. | |
182 if (real_to_path.value().size() >= real_from_path.value().size() && | |
183 real_from_path.IsParent(real_to_path)) { | |
184 return false; | 181 return false; |
185 } | |
186 | 182 |
187 int traverse_type = FileEnumerator::FILES; | 183 int traverse_type = FileEnumerator::FILES; |
188 if (recursive) | 184 if (recursive) |
189 traverse_type |= FileEnumerator::DIRECTORIES; | 185 traverse_type |= FileEnumerator::DIRECTORIES; |
190 FileEnumerator traversal(from_path, recursive, traverse_type); | 186 FileEnumerator traversal(from_path, recursive, traverse_type); |
191 | 187 |
192 if (!PathExists(from_path)) { | 188 if (!PathExists(from_path)) { |
193 DLOG(ERROR) << "CopyDirectory() couldn't stat source directory: " | 189 DLOG(ERROR) << "CopyDirectory() couldn't stat source directory: " |
194 << from_path.value().c_str(); | 190 << from_path.value().c_str(); |
195 return false; | 191 return false; |
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 // Like Move, this function is not transactional, so we just | 820 // Like Move, this function is not transactional, so we just |
825 // leave the copied bits behind if deleting from_path fails. | 821 // leave the copied bits behind if deleting from_path fails. |
826 // If to_path exists previously then we have already overwritten | 822 // If to_path exists previously then we have already overwritten |
827 // it by now, we don't get better off by deleting the new bits. | 823 // it by now, we don't get better off by deleting the new bits. |
828 } | 824 } |
829 return false; | 825 return false; |
830 } | 826 } |
831 | 827 |
832 } // namespace internal | 828 } // namespace internal |
833 } // namespace base | 829 } // namespace base |
OLD | NEW |