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 "webkit/browser/fileapi/file_system_operation_context.h" | 10 #include "webkit/browser/fileapi/file_system_operation_context.h" |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 return make_scoped_ptr(new NativeFileEnumerator( | 166 return make_scoped_ptr(new NativeFileEnumerator( |
167 root_path, recursive, | 167 root_path, recursive, |
168 base::FileEnumerator::FILES | base::FileEnumerator::DIRECTORIES)) | 168 base::FileEnumerator::FILES | base::FileEnumerator::DIRECTORIES)) |
169 .PassAs<FileSystemFileUtil::AbstractFileEnumerator>(); | 169 .PassAs<FileSystemFileUtil::AbstractFileEnumerator>(); |
170 } | 170 } |
171 | 171 |
172 PlatformFileError NativeFileUtil::Touch( | 172 PlatformFileError NativeFileUtil::Touch( |
173 const base::FilePath& path, | 173 const base::FilePath& path, |
174 const base::Time& last_access_time, | 174 const base::Time& last_access_time, |
175 const base::Time& last_modified_time) { | 175 const base::Time& last_modified_time) { |
176 if (!file_util::TouchFile( | 176 if (!base::TouchFile(path, last_access_time, last_modified_time)) |
177 path, last_access_time, last_modified_time)) | |
178 return base::PLATFORM_FILE_ERROR_FAILED; | 177 return base::PLATFORM_FILE_ERROR_FAILED; |
179 return base::PLATFORM_FILE_OK; | 178 return base::PLATFORM_FILE_OK; |
180 } | 179 } |
181 | 180 |
182 PlatformFileError NativeFileUtil::Truncate( | 181 PlatformFileError NativeFileUtil::Truncate( |
183 const base::FilePath& path, int64 length) { | 182 const base::FilePath& path, int64 length) { |
184 PlatformFileError error_code(base::PLATFORM_FILE_ERROR_FAILED); | 183 PlatformFileError error_code(base::PLATFORM_FILE_ERROR_FAILED); |
185 PlatformFile file = | 184 PlatformFile file = |
186 base::CreatePlatformFile( | 185 base::CreatePlatformFile( |
187 path, | 186 path, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 if (!base::CopyFile(src_path, dest_path)) | 236 if (!base::CopyFile(src_path, dest_path)) |
238 return base::PLATFORM_FILE_ERROR_FAILED; | 237 return base::PLATFORM_FILE_ERROR_FAILED; |
239 } else { | 238 } else { |
240 if (!base::Move(src_path, dest_path)) | 239 if (!base::Move(src_path, dest_path)) |
241 return base::PLATFORM_FILE_ERROR_FAILED; | 240 return base::PLATFORM_FILE_ERROR_FAILED; |
242 } | 241 } |
243 | 242 |
244 // Preserve the last modified time. Do not return error here even if | 243 // Preserve the last modified time. Do not return error here even if |
245 // the setting is failed, because the copy itself is successfully done. | 244 // the setting is failed, because the copy itself is successfully done. |
246 if (option == FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED) | 245 if (option == FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED) |
247 file_util::SetLastModifiedTime(dest_path, last_modified); | 246 base::TouchFile(dest_path, last_modified, last_modified); |
248 | 247 |
249 return base::PLATFORM_FILE_OK; | 248 return base::PLATFORM_FILE_OK; |
250 } | 249 } |
251 | 250 |
252 PlatformFileError NativeFileUtil::DeleteFile(const base::FilePath& path) { | 251 PlatformFileError NativeFileUtil::DeleteFile(const base::FilePath& path) { |
253 if (!base::PathExists(path)) | 252 if (!base::PathExists(path)) |
254 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 253 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
255 if (base::DirectoryExists(path)) | 254 if (base::DirectoryExists(path)) |
256 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; | 255 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; |
257 if (!base::DeleteFile(path, false)) | 256 if (!base::DeleteFile(path, false)) |
258 return base::PLATFORM_FILE_ERROR_FAILED; | 257 return base::PLATFORM_FILE_ERROR_FAILED; |
259 return base::PLATFORM_FILE_OK; | 258 return base::PLATFORM_FILE_OK; |
260 } | 259 } |
261 | 260 |
262 PlatformFileError NativeFileUtil::DeleteDirectory(const base::FilePath& path) { | 261 PlatformFileError NativeFileUtil::DeleteDirectory(const base::FilePath& path) { |
263 if (!base::PathExists(path)) | 262 if (!base::PathExists(path)) |
264 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 263 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
265 if (!base::DirectoryExists(path)) | 264 if (!base::DirectoryExists(path)) |
266 return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; | 265 return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; |
267 if (!base::IsDirectoryEmpty(path)) | 266 if (!base::IsDirectoryEmpty(path)) |
268 return base::PLATFORM_FILE_ERROR_NOT_EMPTY; | 267 return base::PLATFORM_FILE_ERROR_NOT_EMPTY; |
269 if (!base::DeleteFile(path, false)) | 268 if (!base::DeleteFile(path, false)) |
270 return base::PLATFORM_FILE_ERROR_FAILED; | 269 return base::PLATFORM_FILE_ERROR_FAILED; |
271 return base::PLATFORM_FILE_OK; | 270 return base::PLATFORM_FILE_OK; |
272 } | 271 } |
273 | 272 |
274 } // namespace fileapi | 273 } // namespace fileapi |
OLD | NEW |