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::Error NativeFileUtil::CreateOrOpen(const base::FilePath& path, |
126 const base::FilePath& path, int file_flags, | 126 int file_flags, |
127 PlatformFile* file_handle, bool* created) { | 127 base::File* file) { |
128 DCHECK(!file->IsValid()); | |
128 if (!base::DirectoryExists(path.DirName())) { | 129 if (!base::DirectoryExists(path.DirName())) { |
rvargas (doing something else)
2014/03/21 22:39:21
Is there a platform where this would not fail duri
kinuko
2014/03/24 09:56:58
The latter. (The main purpose of having this thin
rvargas (doing something else)
2014/03/24 23:02:48
I'm still curious about it. Are we promising a par
kinuko
2014/03/25 03:15:26
These error codes are basically following this spe
rvargas (doing something else)
2014/03/26 00:35:46
There are not that many error codes on that doc so
| |
129 // If its parent does not exist, should return NOT_FOUND error. | 130 // If its parent does not exist, should return NOT_FOUND error. |
130 return base::File::FILE_ERROR_NOT_FOUND; | 131 return base::File::FILE_ERROR_NOT_FOUND; |
131 } | 132 } |
132 if (base::DirectoryExists(path)) | 133 if (base::DirectoryExists(path)) |
133 return base::File::FILE_ERROR_NOT_A_FILE; | 134 return base::File::FILE_ERROR_NOT_A_FILE; |
rvargas (doing something else)
2014/03/21 22:39:21
Maybe there should be an explicit flag for opening
| |
134 | 135 |
135 // TODO(rvargas): convert this code to use base::File. | 136 *file = base::File(path, file_flags); |
136 base::PlatformFileError error_code = base::PLATFORM_FILE_OK; | 137 if (file->IsValid()) |
137 *file_handle = base::CreatePlatformFile(path, file_flags, | 138 return base::File::FILE_OK; |
138 created, &error_code); | 139 return file->error_details(); |
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 } | 140 } |
147 | 141 |
148 base::File::Error NativeFileUtil::EnsureFileExists( | 142 base::File::Error NativeFileUtil::EnsureFileExists( |
149 const base::FilePath& path, | 143 const base::FilePath& path, |
150 bool* created) { | 144 bool* created) { |
151 if (!base::DirectoryExists(path.DirName())) | 145 if (!base::DirectoryExists(path.DirName())) |
152 // If its parent does not exist, should return NOT_FOUND error. | 146 // If its parent does not exist, should return NOT_FOUND error. |
153 return base::File::FILE_ERROR_NOT_FOUND; | 147 return base::File::FILE_ERROR_NOT_FOUND; |
154 | 148 |
155 // Tries to create the |path| exclusively. This should fail | 149 // 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)) | 310 if (!base::DirectoryExists(path)) |
317 return base::File::FILE_ERROR_NOT_A_DIRECTORY; | 311 return base::File::FILE_ERROR_NOT_A_DIRECTORY; |
318 if (!base::IsDirectoryEmpty(path)) | 312 if (!base::IsDirectoryEmpty(path)) |
319 return base::File::FILE_ERROR_NOT_EMPTY; | 313 return base::File::FILE_ERROR_NOT_EMPTY; |
320 if (!base::DeleteFile(path, false)) | 314 if (!base::DeleteFile(path, false)) |
321 return base::File::FILE_ERROR_FAILED; | 315 return base::File::FILE_ERROR_FAILED; |
322 return base::File::FILE_OK; | 316 return base::File::FILE_OK; |
323 } | 317 } |
324 | 318 |
325 } // namespace fileapi | 319 } // namespace fileapi |
OLD | NEW |