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_file_system.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <sys/stat.h> | |
8 | 9 |
9 #include <utility> | 10 #include <utility> |
10 | 11 |
11 #include "base/bind.h" | 12 #include "base/bind.h" |
12 #include "base/chromeos/chromeos_version.h" | 13 #include "base/chromeos/chromeos_version.h" |
13 #include "base/eintr_wrapper.h" | 14 #include "base/eintr_wrapper.h" |
14 #include "base/file_util.h" | 15 #include "base/file_util.h" |
15 #include "base/json/json_file_value_serializer.h" | 16 #include "base/json/json_file_value_serializer.h" |
16 #include "base/json/json_reader.h" | 17 #include "base/json/json_reader.h" |
17 #include "base/json/json_writer.h" | 18 #include "base/json/json_writer.h" |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 << ": \"" << strerror(errno) | 198 << ": \"" << strerror(errno) |
198 << "\", " << error; | 199 << "\", " << error; |
199 } else { | 200 } else { |
200 DVLOG(1) << "Created dir " << paths_to_create[i].value(); | 201 DVLOG(1) << "Created dir " << paths_to_create[i].value(); |
201 } | 202 } |
202 } | 203 } |
203 | 204 |
204 return error; | 205 return error; |
205 } | 206 } |
206 | 207 |
208 // Changes the permissions of |file_path| to |permissions|. | |
209 // Returns the platform error code of the operation. | |
210 base::PlatformFileError ChangeFilePermissions(const FilePath& file_path, | |
211 mode_t permissions) { | |
212 base::PlatformFileError error = base::PLATFORM_FILE_OK; | |
213 | |
214 if (chmod(file_path.value().c_str(), permissions) != 0) { | |
satorux1
2012/04/13 06:09:23
Please use HANDLE_EINTR when issuing a system call
Ben Chan
2012/04/13 06:30:27
Done.
| |
215 error = SystemToPlatformError(errno); | |
216 PLOG(ERROR) << "Error changing permissions of " << file_path.value(); | |
217 } else { | |
218 DVLOG(1) << "Changed permissions of " << file_path.value(); | |
219 } | |
220 | |
221 return error; | |
222 } | |
223 | |
207 // Modifies cache state of file on IO thread pool, which involves: | 224 // Modifies cache state of file on IO thread pool, which involves: |
208 // - moving or copying file (per |file_operation_type|) from |source_path| to | 225 // - moving or copying file (per |file_operation_type|) from |source_path| to |
209 // |dest_path| if they're different | 226 // |dest_path| if they're different |
210 // - deleting symlink if |symlink_path| is not empty | 227 // - deleting symlink if |symlink_path| is not empty |
211 // - creating symlink if |symlink_path| is not empty and |create_symlink| is | 228 // - creating symlink if |symlink_path| is not empty and |create_symlink| is |
212 // true. | 229 // true. |
213 base::PlatformFileError ModifyCacheState( | 230 base::PlatformFileError ModifyCacheState( |
214 const FilePath& source_path, | 231 const FilePath& source_path, |
215 const FilePath& dest_path, | 232 const FilePath& dest_path, |
216 GDataFileSystem::FileOperationType file_operation_type, | 233 GDataFileSystem::FileOperationType file_operation_type, |
(...skipping 3025 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3242 void GDataFileSystem::InitializeCacheIfNecessary() { | 3259 void GDataFileSystem::InitializeCacheIfNecessary() { |
3243 // Lock to access cache_initialization_started_; | 3260 // Lock to access cache_initialization_started_; |
3244 base::AutoLock lock(lock_); | 3261 base::AutoLock lock(lock_); |
3245 UnsafeInitializeCacheIfNecessary(); | 3262 UnsafeInitializeCacheIfNecessary(); |
3246 } | 3263 } |
3247 | 3264 |
3248 //========= GDataFileSystem: Cache tasks that ran on io thread pool ============ | 3265 //========= GDataFileSystem: Cache tasks that ran on io thread pool ============ |
3249 | 3266 |
3250 void GDataFileSystem::InitializeCacheOnIOThreadPool() { | 3267 void GDataFileSystem::InitializeCacheOnIOThreadPool() { |
3251 base::PlatformFileError error = CreateCacheDirectories(cache_paths_); | 3268 base::PlatformFileError error = CreateCacheDirectories(cache_paths_); |
3252 | |
3253 if (error != base::PLATFORM_FILE_OK) | 3269 if (error != base::PLATFORM_FILE_OK) |
3254 return; | 3270 return; |
3255 | 3271 |
3272 // Change permissions of cache persistent directory to u+rwx,og+x in order to | |
3273 // allow archive files in that directory to be mounted by cros-disks. | |
3274 error = ChangeFilePermissions( | |
3275 cache_paths_[GDataRootDirectory::CACHE_TYPE_PERSISTENT], | |
3276 S_IRWXU | S_IXGRP | S_IXOTH); | |
3277 if (error != base::PLATFORM_FILE_OK) | |
3278 return; | |
3279 | |
3256 // Scan cache persistent and tmp directories to enumerate all files and create | 3280 // Scan cache persistent and tmp directories to enumerate all files and create |
3257 // corresponding entries for cache map. | 3281 // corresponding entries for cache map. |
3258 GDataRootDirectory::CacheMap cache_map; | 3282 GDataRootDirectory::CacheMap cache_map; |
3259 ScanCacheDirectory(GDataRootDirectory::CACHE_TYPE_PERSISTENT, &cache_map); | 3283 ScanCacheDirectory(GDataRootDirectory::CACHE_TYPE_PERSISTENT, &cache_map); |
3260 ScanCacheDirectory(GDataRootDirectory::CACHE_TYPE_TMP, &cache_map); | 3284 ScanCacheDirectory(GDataRootDirectory::CACHE_TYPE_TMP, &cache_map); |
3261 | 3285 |
3262 // Then scan pinned and outgoing directories to update existing entries in | 3286 // Then scan pinned and outgoing directories to update existing entries in |
3263 // cache map, or create new ones for pinned symlinks to /dev/null which target | 3287 // cache map, or create new ones for pinned symlinks to /dev/null which target |
3264 // nothing. | 3288 // nothing. |
3265 // Pinned and outgoing directories should be scanned after the persistent | 3289 // Pinned and outgoing directories should be scanned after the persistent |
(...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4140 pref_registrar_->Init(profile_->GetPrefs()); | 4164 pref_registrar_->Init(profile_->GetPrefs()); |
4141 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); | 4165 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); |
4142 } | 4166 } |
4143 | 4167 |
4144 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { | 4168 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { |
4145 delete global_free_disk_getter_for_testing; // Safe to delete NULL; | 4169 delete global_free_disk_getter_for_testing; // Safe to delete NULL; |
4146 global_free_disk_getter_for_testing = getter; | 4170 global_free_disk_getter_for_testing = getter; |
4147 } | 4171 } |
4148 | 4172 |
4149 } // namespace gdata | 4173 } // namespace gdata |
OLD | NEW |