cache_util_posix.cc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright (c) 2011 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 "net/disk_cache/cache_util.h"
  5. #include "base/files/file_enumerator.h"
  6. #include "base/files/file_util.h"
  7. #include "base/logging.h"
  8. #include "base/strings/string_util.h"
  9. #include "build/chromeos_buildflags.h"
  10. namespace disk_cache {
  11. bool MoveCache(const base::FilePath& from_path, const base::FilePath& to_path) {
  12. #if BUILDFLAG(IS_CHROMEOS_ASH)
  13. // For ChromeOS, we don't actually want to rename the cache
  14. // directory, because if we do, then it'll get recreated through the
  15. // encrypted filesystem (with encrypted names), and we won't be able
  16. // to see these directories anymore in an unmounted encrypted
  17. // filesystem, so we just move each item in the cache to a new
  18. // directory.
  19. if (!base::CreateDirectory(to_path)) {
  20. LOG(ERROR) << "Unable to create destination cache directory.";
  21. return false;
  22. }
  23. base::FileEnumerator iter(from_path, false /* not recursive */,
  24. base::FileEnumerator::DIRECTORIES | base::FileEnumerator::FILES);
  25. for (base::FilePath name = iter.Next(); !name.value().empty();
  26. name = iter.Next()) {
  27. base::FilePath destination = to_path.Append(name.BaseName());
  28. if (!base::Move(name, destination)) {
  29. LOG(ERROR) << "Unable to move cache item.";
  30. return false;
  31. }
  32. }
  33. return true;
  34. #else
  35. return base::Move(from_path, to_path);
  36. #endif
  37. }
  38. } // namespace disk_cache