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 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 const std::vector<FilePath>& paths_to_create) { | 186 const std::vector<FilePath>& paths_to_create) { |
187 base::PlatformFileError error = base::PLATFORM_FILE_OK; | 187 base::PlatformFileError error = base::PLATFORM_FILE_OK; |
188 | 188 |
189 for (size_t i = 0; i < paths_to_create.size(); ++i) { | 189 for (size_t i = 0; i < paths_to_create.size(); ++i) { |
190 if (file_util::DirectoryExists(paths_to_create[i])) | 190 if (file_util::DirectoryExists(paths_to_create[i])) |
191 continue; | 191 continue; |
192 | 192 |
193 if (!file_util::CreateDirectory(paths_to_create[i])) { | 193 if (!file_util::CreateDirectory(paths_to_create[i])) { |
194 // Error creating this directory, record error and proceed with next one. | 194 // Error creating this directory, record error and proceed with next one. |
195 error = SystemToPlatformError(errno); | 195 error = SystemToPlatformError(errno); |
196 LOG(ERROR) << "Error creating dir " << paths_to_create[i].value() | 196 PLOG(ERROR) << "Error creating directory " << paths_to_create[i].value(); |
197 << ": \"" << strerror(errno) | |
198 << "\", " << error; | |
199 } else { | 197 } else { |
200 DVLOG(1) << "Created dir " << paths_to_create[i].value(); | 198 DVLOG(1) << "Created directory " << paths_to_create[i].value(); |
201 } | 199 } |
202 } | 200 } |
203 | 201 |
204 return error; | 202 return error; |
205 } | 203 } |
206 | 204 |
207 // Modifies cache state of file on IO thread pool, which involves: | 205 // Modifies cache state of file on IO thread pool, which involves: |
208 // - moving or copying file (per |file_operation_type|) from |source_path| to | 206 // - moving or copying file (per |file_operation_type|) from |source_path| to |
209 // |dest_path| if they're different | 207 // |dest_path| if they're different |
210 // - deleting symlink if |symlink_path| is not empty | 208 // - deleting symlink if |symlink_path| is not empty |
211 // - creating symlink if |symlink_path| is not empty and |create_symlink| is | 209 // - creating symlink if |symlink_path| is not empty and |create_symlink| is |
212 // true. | 210 // true. |
213 base::PlatformFileError ModifyCacheState( | 211 base::PlatformFileError ModifyCacheState( |
214 const FilePath& source_path, | 212 const FilePath& source_path, |
215 const FilePath& dest_path, | 213 const FilePath& dest_path, |
216 GDataFileSystem::FileOperationType file_operation_type, | 214 GDataFileSystem::FileOperationType file_operation_type, |
217 const FilePath& symlink_path, | 215 const FilePath& symlink_path, |
218 bool create_symlink) { | 216 bool create_symlink) { |
219 // Move or copy |source_path| to |dest_path| if they are different. | 217 // Move or copy |source_path| to |dest_path| if they are different. |
220 if (source_path != dest_path) { | 218 if (source_path != dest_path) { |
221 bool success = false; | 219 bool success = false; |
222 if (file_operation_type == GDataFileSystem::FILE_OPERATION_MOVE) | 220 if (file_operation_type == GDataFileSystem::FILE_OPERATION_MOVE) |
223 success = file_util::Move(source_path, dest_path); | 221 success = file_util::Move(source_path, dest_path); |
224 else if (file_operation_type == | 222 else if (file_operation_type == |
225 GDataFileSystem::FILE_OPERATION_COPY) | 223 GDataFileSystem::FILE_OPERATION_COPY) |
226 success = file_util::CopyFile(source_path, dest_path); | 224 success = file_util::CopyFile(source_path, dest_path); |
227 if (!success) { | 225 if (!success) { |
228 base::PlatformFileError error = SystemToPlatformError(errno); | 226 base::PlatformFileError error = SystemToPlatformError(errno); |
229 LOG(ERROR) << "Error " | 227 PLOG(ERROR) << "Error " |
230 << (file_operation_type == | 228 << (file_operation_type == |
231 GDataFileSystem::FILE_OPERATION_MOVE ? | 229 GDataFileSystem::FILE_OPERATION_MOVE ? |
232 "moving " : "copying ") | 230 "moving " : "copying ") |
233 << source_path.value() | 231 << source_path.value() |
234 << " to " << dest_path.value() | 232 << " to " << dest_path.value(); |
235 << ": " << strerror(errno); | |
236 return error; | 233 return error; |
237 } else { | 234 } else { |
238 DVLOG(1) << (file_operation_type == | 235 DVLOG(1) << (file_operation_type == |
239 GDataFileSystem::FILE_OPERATION_MOVE ? | 236 GDataFileSystem::FILE_OPERATION_MOVE ? |
240 "Moved " : "Copied ") | 237 "Moved " : "Copied ") |
241 << source_path.value() | 238 << source_path.value() |
242 << " to " << dest_path.value(); | 239 << " to " << dest_path.value(); |
243 } | 240 } |
244 } else { | 241 } else { |
245 DVLOG(1) << "No need to move file: source = destination"; | 242 DVLOG(1) << "No need to move file: source = destination"; |
(...skipping 26 matching lines...) Expand all Loading... |
272 | 269 |
273 // We try to save one file operation by not checking if link exists before | 270 // We try to save one file operation by not checking if link exists before |
274 // deleting it, so unlink may return error if link doesn't exist, but it | 271 // deleting it, so unlink may return error if link doesn't exist, but it |
275 // doesn't really matter to us. | 272 // doesn't really matter to us. |
276 bool deleted = HANDLE_EINTR(unlink(symlink_path.value().c_str())) == 0; | 273 bool deleted = HANDLE_EINTR(unlink(symlink_path.value().c_str())) == 0; |
277 if (deleted) { | 274 if (deleted) { |
278 DVLOG(1) << "Deleted symlink " << symlink_path.value(); | 275 DVLOG(1) << "Deleted symlink " << symlink_path.value(); |
279 } else { | 276 } else { |
280 // Since we didn't check if symlink exists before deleting it, don't log | 277 // Since we didn't check if symlink exists before deleting it, don't log |
281 // if symlink doesn't exist. | 278 // if symlink doesn't exist. |
282 if (errno != ENOENT) { | 279 if (errno != ENOENT) |
283 LOG(WARNING) << "Error deleting symlink " << symlink_path.value() | 280 PLOG(WARNING) << "Error deleting symlink " << symlink_path.value(); |
284 << ": " << strerror(errno); | |
285 } | |
286 } | 281 } |
287 | 282 |
288 if (!create_symlink) | 283 if (!create_symlink) |
289 return base::PLATFORM_FILE_OK; | 284 return base::PLATFORM_FILE_OK; |
290 | 285 |
291 // Create new symlink to |dest_path|. | 286 // Create new symlink to |dest_path|. |
292 if (!file_util::CreateSymbolicLink(dest_path, symlink_path)) { | 287 if (!file_util::CreateSymbolicLink(dest_path, symlink_path)) { |
293 base::PlatformFileError error = SystemToPlatformError(errno); | 288 base::PlatformFileError error = SystemToPlatformError(errno); |
294 LOG(ERROR) << "Error creating symlink " << symlink_path.value() | 289 PLOG(ERROR) << "Error creating symlink " << symlink_path.value() |
295 << " for " << dest_path.value() | 290 << " for " << dest_path.value(); |
296 << ": " << strerror(errno); | |
297 return error; | 291 return error; |
298 } else { | 292 } else { |
299 DVLOG(1) << "Created symlink " << symlink_path.value() | 293 DVLOG(1) << "Created symlink " << symlink_path.value() |
300 << " to " << dest_path.value(); | 294 << " to " << dest_path.value(); |
301 } | 295 } |
302 | 296 |
303 return base::PLATFORM_FILE_OK; | 297 return base::PLATFORM_FILE_OK; |
304 } | 298 } |
305 | 299 |
306 // Deletes all files that match |path_to_delete_pattern| except for | 300 // Deletes all files that match |path_to_delete_pattern| except for |
(...skipping 3833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4140 pref_registrar_->Init(profile_->GetPrefs()); | 4134 pref_registrar_->Init(profile_->GetPrefs()); |
4141 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); | 4135 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); |
4142 } | 4136 } |
4143 | 4137 |
4144 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { | 4138 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { |
4145 delete global_free_disk_getter_for_testing; // Safe to delete NULL; | 4139 delete global_free_disk_getter_for_testing; // Safe to delete NULL; |
4146 global_free_disk_getter_for_testing = getter; | 4140 global_free_disk_getter_for_testing = getter; |
4147 } | 4141 } |
4148 | 4142 |
4149 } // namespace gdata | 4143 } // namespace gdata |
OLD | NEW |