legacy_directory_deletion.cc 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/sync/base/legacy_directory_deletion.h"
  5. #include "base/files/file_enumerator.h"
  6. #include "base/files/file_util.h"
  7. #include "base/logging.h"
  8. namespace syncer {
  9. // Delete the directory database files from the sync data folder to cleanup
  10. // all files. The main purpose is to delete the legacy Directory files (sqlite)
  11. // but it also currently deletes the files corresponding to the modern
  12. // NigoriStorageImpl.
  13. void DeleteLegacyDirectoryFilesAndNigoriStorage(
  14. const base::FilePath& directory_path) {
  15. // We assume that the directory database files are all top level files, and
  16. // use no folders. We also assume that there might be child folders under
  17. // |directory_path| that are used for non-directory things, like storing
  18. // ModelTypeStore/LevelDB data, and we expressly do not want to delete those.
  19. if (!base::DirectoryExists(directory_path)) {
  20. return;
  21. }
  22. base::FileEnumerator fe(directory_path, false, base::FileEnumerator::FILES);
  23. for (base::FilePath current = fe.Next(); !current.empty();
  24. current = fe.Next()) {
  25. if (!base::DeleteFile(current)) {
  26. DLOG(ERROR) << "Could not delete all sync directory files.";
  27. }
  28. }
  29. }
  30. } // namespace syncer