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_metadata.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_cache_metadata.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 8 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
9 | 9 |
10 namespace gdata { | 10 namespace gdata { |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 // Changes the permissions of |file_path| to |permissions|. | |
15 bool ChangeFilePermissions(const FilePath& file_path, mode_t permissions) { | |
16 if (HANDLE_EINTR(chmod(file_path.value().c_str(), permissions)) != 0) { | |
17 PLOG(ERROR) << "Error changing permissions of " << file_path.value(); | |
18 return false; | |
19 } | |
20 DVLOG(1) << "Changed permissions of " << file_path.value(); | |
21 return true; | |
22 } | |
23 | |
24 // Returns true if |file_path| is a valid symbolic link as |sub_dir_type|. | 14 // Returns true if |file_path| is a valid symbolic link as |sub_dir_type|. |
25 // Otherwise, returns false with the reason. | 15 // Otherwise, returns false with the reason. |
26 bool IsValidSymbolicLink(const FilePath& file_path, | 16 bool IsValidSymbolicLink(const FilePath& file_path, |
27 GDataCache::CacheSubDirectoryType sub_dir_type, | 17 GDataCache::CacheSubDirectoryType sub_dir_type, |
28 const std::vector<FilePath>& cache_paths, | 18 const std::vector<FilePath>& cache_paths, |
29 std::string* reason) { | 19 std::string* reason) { |
30 DCHECK(sub_dir_type == GDataCache::CACHE_TYPE_PINNED || | 20 DCHECK(sub_dir_type == GDataCache::CACHE_TYPE_PINNED || |
31 sub_dir_type == GDataCache::CACHE_TYPE_OUTGOING); | 21 sub_dir_type == GDataCache::CACHE_TYPE_OUTGOING); |
32 | 22 |
33 FilePath destination; | 23 FilePath destination; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 if (cache_paths.size() < GDataCache::NUM_CACHE_TYPES) { | 122 if (cache_paths.size() < GDataCache::NUM_CACHE_TYPES) { |
133 LOG(ERROR) << "Size of cache_paths is invalid."; | 123 LOG(ERROR) << "Size of cache_paths is invalid."; |
134 return; | 124 return; |
135 } | 125 } |
136 | 126 |
137 if (!GDataCache::CreateCacheDirectories(cache_paths)) | 127 if (!GDataCache::CreateCacheDirectories(cache_paths)) |
138 return; | 128 return; |
139 | 129 |
140 // Change permissions of cache persistent directory to u+rwx,og+x in order to | 130 // Change permissions of cache persistent directory to u+rwx,og+x in order to |
141 // allow archive files in that directory to be mounted by cros-disks. | 131 // allow archive files in that directory to be mounted by cros-disks. |
142 if (!ChangeFilePermissions(cache_paths[GDataCache::CACHE_TYPE_PERSISTENT], | 132 if (!file_util::SetPosixFilePermissions( |
143 S_IRWXU | S_IXGRP | S_IXOTH)) | 133 cache_paths[GDataCache::CACHE_TYPE_PERSISTENT], |
| 134 S_IRWXU | S_IXGRP | S_IXOTH)) |
144 return; | 135 return; |
145 | 136 |
146 DVLOG(1) << "Scanning directories"; | 137 DVLOG(1) << "Scanning directories"; |
147 | 138 |
148 // Scan cache persistent and tmp directories to enumerate all files and create | 139 // Scan cache persistent and tmp directories to enumerate all files and create |
149 // corresponding entries for cache map. | 140 // corresponding entries for cache map. |
150 ResourceIdToFilePathMap persistent_file_map; | 141 ResourceIdToFilePathMap persistent_file_map; |
151 ScanCacheDirectory(cache_paths, | 142 ScanCacheDirectory(cache_paths, |
152 GDataCache::CACHE_TYPE_PERSISTENT, | 143 GDataCache::CACHE_TYPE_PERSISTENT, |
153 &cache_map_, | 144 &cache_map_, |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 // If the MD5 matching is not requested, don't check MD5. | 399 // If the MD5 matching is not requested, don't check MD5. |
409 return true; | 400 return true; |
410 } else if (md5 == cache_entry.md5) { | 401 } else if (md5 == cache_entry.md5) { |
411 // Otherwise, compare the MD5. | 402 // Otherwise, compare the MD5. |
412 return true; | 403 return true; |
413 } | 404 } |
414 return false; | 405 return false; |
415 } | 406 } |
416 | 407 |
417 } // namespace gdata | 408 } // namespace gdata |
OLD | NEW |