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