Chromium Code Reviews| 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 "webkit/browser/fileapi/native_file_util.h" | 5 #include "webkit/browser/fileapi/native_file_util.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/files/file_enumerator.h" | 8 #include "base/files/file_enumerator.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "net/base/file_stream.h" | 10 #include "net/base/file_stream.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 | 115 |
| 116 NativeFileUtil::CopyOrMoveMode NativeFileUtil::CopyOrMoveModeForDestination( | 116 NativeFileUtil::CopyOrMoveMode NativeFileUtil::CopyOrMoveModeForDestination( |
| 117 const FileSystemURL& dest_url, bool copy) { | 117 const FileSystemURL& dest_url, bool copy) { |
| 118 if (copy) { | 118 if (copy) { |
| 119 return dest_url.mount_option().copy_sync_option() == COPY_SYNC_OPTION_SYNC ? | 119 return dest_url.mount_option().copy_sync_option() == COPY_SYNC_OPTION_SYNC ? |
| 120 COPY_SYNC : COPY_NOSYNC; | 120 COPY_SYNC : COPY_NOSYNC; |
| 121 } | 121 } |
| 122 return MOVE; | 122 return MOVE; |
| 123 } | 123 } |
| 124 | 124 |
| 125 base::File::Error NativeFileUtil::CreateOrOpen( | 125 base::File NativeFileUtil::CreateOrOpen(const base::FilePath& path, |
| 126 const base::FilePath& path, int file_flags, | 126 int file_flags) { |
| 127 PlatformFile* file_handle, bool* created) { | |
| 128 if (!base::DirectoryExists(path.DirName())) { | 127 if (!base::DirectoryExists(path.DirName())) { |
| 129 // If its parent does not exist, should return NOT_FOUND error. | 128 // If its parent does not exist, should return NOT_FOUND error. |
| 130 return base::File::FILE_ERROR_NOT_FOUND; | 129 return base::File(base::File::FILE_ERROR_NOT_FOUND); |
|
kinuko
2014/03/26 03:35:06
Ah, ok, to return a specific error.. (I think I mi
| |
| 131 } | 130 } |
| 131 | |
| 132 // TODO(rvargas): Check |file_flags| instead. See bug 356358. | |
| 132 if (base::DirectoryExists(path)) | 133 if (base::DirectoryExists(path)) |
| 133 return base::File::FILE_ERROR_NOT_A_FILE; | 134 return base::File(base::File::FILE_ERROR_NOT_A_FILE); |
| 134 | 135 |
| 135 // TODO(rvargas): convert this code to use base::File. | 136 return base::File(path, file_flags); |
| 136 base::PlatformFileError error_code = base::PLATFORM_FILE_OK; | |
| 137 *file_handle = base::CreatePlatformFile(path, file_flags, | |
| 138 created, &error_code); | |
| 139 return static_cast<base::File::Error>(error_code); | |
| 140 } | |
| 141 | |
| 142 base::File::Error NativeFileUtil::Close(PlatformFile file_handle) { | |
| 143 if (!base::ClosePlatformFile(file_handle)) | |
| 144 return base::File::FILE_ERROR_FAILED; | |
| 145 return base::File::FILE_OK; | |
| 146 } | 137 } |
| 147 | 138 |
| 148 base::File::Error NativeFileUtil::EnsureFileExists( | 139 base::File::Error NativeFileUtil::EnsureFileExists( |
| 149 const base::FilePath& path, | 140 const base::FilePath& path, |
| 150 bool* created) { | 141 bool* created) { |
| 151 if (!base::DirectoryExists(path.DirName())) | 142 if (!base::DirectoryExists(path.DirName())) |
| 152 // If its parent does not exist, should return NOT_FOUND error. | 143 // If its parent does not exist, should return NOT_FOUND error. |
| 153 return base::File::FILE_ERROR_NOT_FOUND; | 144 return base::File::FILE_ERROR_NOT_FOUND; |
| 154 | 145 |
| 155 // Tries to create the |path| exclusively. This should fail | 146 // Tries to create the |path| exclusively. This should fail |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 if (!base::DirectoryExists(path)) | 307 if (!base::DirectoryExists(path)) |
| 317 return base::File::FILE_ERROR_NOT_A_DIRECTORY; | 308 return base::File::FILE_ERROR_NOT_A_DIRECTORY; |
| 318 if (!base::IsDirectoryEmpty(path)) | 309 if (!base::IsDirectoryEmpty(path)) |
| 319 return base::File::FILE_ERROR_NOT_EMPTY; | 310 return base::File::FILE_ERROR_NOT_EMPTY; |
| 320 if (!base::DeleteFile(path, false)) | 311 if (!base::DeleteFile(path, false)) |
| 321 return base::File::FILE_ERROR_FAILED; | 312 return base::File::FILE_ERROR_FAILED; |
| 322 return base::File::FILE_OK; | 313 return base::File::FILE_OK; |
| 323 } | 314 } |
| 324 | 315 |
| 325 } // namespace fileapi | 316 } // namespace fileapi |
| OLD | NEW |