| 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 "chrome/browser/chromeos/gdata/gdata_cache.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_cache.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/chromeos/chromeos_version.h" | 9 #include "base/chromeos/chromeos_version.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 // Deletes all files that match |path_to_delete_pattern| except for | 163 // Deletes all files that match |path_to_delete_pattern| except for |
| 164 // |path_to_keep| on blocking pool. | 164 // |path_to_keep| on blocking pool. |
| 165 // If |path_to_keep| is empty, all files in |path_to_delete_pattern| are | 165 // If |path_to_keep| is empty, all files in |path_to_delete_pattern| are |
| 166 // deleted. | 166 // deleted. |
| 167 void DeleteFilesSelectively(const FilePath& path_to_delete_pattern, | 167 void DeleteFilesSelectively(const FilePath& path_to_delete_pattern, |
| 168 const FilePath& path_to_keep) { | 168 const FilePath& path_to_keep) { |
| 169 // Enumerate all files in directory of |path_to_delete_pattern| that match | 169 // Enumerate all files in directory of |path_to_delete_pattern| that match |
| 170 // base name of |path_to_delete_pattern|. | 170 // base name of |path_to_delete_pattern|. |
| 171 // If a file is not |path_to_keep|, delete it. | 171 // If a file is not |path_to_keep|, delete it. |
| 172 bool success = true; | 172 bool success = true; |
| 173 file_util::FileEnumerator enumerator( | 173 file_util::FileEnumerator enumerator(path_to_delete_pattern.DirName(), |
| 174 path_to_delete_pattern.DirName(), | |
| 175 false, // not recursive | 174 false, // not recursive |
| 176 static_cast<file_util::FileEnumerator::FileType>( | 175 file_util::FileEnumerator::FILES | |
| 177 file_util::FileEnumerator::FILES | | 176 file_util::FileEnumerator::SHOW_SYM_LINKS, |
| 178 file_util::FileEnumerator::SHOW_SYM_LINKS), | |
| 179 path_to_delete_pattern.BaseName().value()); | 177 path_to_delete_pattern.BaseName().value()); |
| 180 for (FilePath current = enumerator.Next(); !current.empty(); | 178 for (FilePath current = enumerator.Next(); !current.empty(); |
| 181 current = enumerator.Next()) { | 179 current = enumerator.Next()) { |
| 182 // If |path_to_keep| is not empty and same as current, don't delete it. | 180 // If |path_to_keep| is not empty and same as current, don't delete it. |
| 183 if (!path_to_keep.empty() && current == path_to_keep) | 181 if (!path_to_keep.empty() && current == path_to_keep) |
| 184 continue; | 182 continue; |
| 185 | 183 |
| 186 success = file_util::Delete(current, false); | 184 success = file_util::Delete(current, false); |
| 187 if (!success) | 185 if (!success) |
| 188 DVLOG(1) << "Error deleting " << current.value(); | 186 DVLOG(1) << "Error deleting " << current.value(); |
| (...skipping 1392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1581 const GDataCacheEntry& cache_entry) { | 1579 const GDataCacheEntry& cache_entry) { |
| 1582 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; | 1580 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; |
| 1583 } | 1581 } |
| 1584 | 1582 |
| 1585 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { | 1583 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { |
| 1586 delete global_free_disk_getter_for_testing; // Safe to delete NULL; | 1584 delete global_free_disk_getter_for_testing; // Safe to delete NULL; |
| 1587 global_free_disk_getter_for_testing = getter; | 1585 global_free_disk_getter_for_testing = getter; |
| 1588 } | 1586 } |
| 1589 | 1587 |
| 1590 } // namespace gdata | 1588 } // namespace gdata |
| OLD | NEW |