| 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 119   if (handle != base::kInvalidPlatformFileValue) | 119   if (handle != base::kInvalidPlatformFileValue) | 
| 120     base::ClosePlatformFile(handle); | 120     base::ClosePlatformFile(handle); | 
| 121   return error_code; | 121   return error_code; | 
| 122 } | 122 } | 
| 123 | 123 | 
| 124 PlatformFileError NativeFileUtil::CreateDirectory( | 124 PlatformFileError NativeFileUtil::CreateDirectory( | 
| 125     const base::FilePath& path, | 125     const base::FilePath& path, | 
| 126     bool exclusive, | 126     bool exclusive, | 
| 127     bool recursive) { | 127     bool recursive) { | 
| 128   // If parent dir of file doesn't exist. | 128   // If parent dir of file doesn't exist. | 
| 129   if (!recursive && !file_util::PathExists(path.DirName())) | 129   if (!recursive && !base::PathExists(path.DirName())) | 
| 130     return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 130     return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 
| 131 | 131 | 
| 132   bool path_exists = file_util::PathExists(path); | 132   bool path_exists = base::PathExists(path); | 
| 133   if (exclusive && path_exists) | 133   if (exclusive && path_exists) | 
| 134     return base::PLATFORM_FILE_ERROR_EXISTS; | 134     return base::PLATFORM_FILE_ERROR_EXISTS; | 
| 135 | 135 | 
| 136   // If file exists at the path. | 136   // If file exists at the path. | 
| 137   if (path_exists && !file_util::DirectoryExists(path)) | 137   if (path_exists && !file_util::DirectoryExists(path)) | 
| 138     return base::PLATFORM_FILE_ERROR_EXISTS; | 138     return base::PLATFORM_FILE_ERROR_EXISTS; | 
| 139 | 139 | 
| 140   if (!file_util::CreateDirectory(path)) | 140   if (!file_util::CreateDirectory(path)) | 
| 141     return base::PLATFORM_FILE_ERROR_FAILED; | 141     return base::PLATFORM_FILE_ERROR_FAILED; | 
| 142 | 142 | 
| 143   if (!SetPlatformSpecificDirectoryPermissions(path)) | 143   if (!SetPlatformSpecificDirectoryPermissions(path)) | 
| 144     return base::PLATFORM_FILE_ERROR_FAILED; | 144     return base::PLATFORM_FILE_ERROR_FAILED; | 
| 145 | 145 | 
| 146   return base::PLATFORM_FILE_OK; | 146   return base::PLATFORM_FILE_OK; | 
| 147 } | 147 } | 
| 148 | 148 | 
| 149 PlatformFileError NativeFileUtil::GetFileInfo( | 149 PlatformFileError NativeFileUtil::GetFileInfo( | 
| 150     const base::FilePath& path, | 150     const base::FilePath& path, | 
| 151     base::PlatformFileInfo* file_info) { | 151     base::PlatformFileInfo* file_info) { | 
| 152   if (!file_util::PathExists(path)) | 152   if (!base::PathExists(path)) | 
| 153     return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 153     return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 
| 154   if (!file_util::GetFileInfo(path, file_info)) | 154   if (!file_util::GetFileInfo(path, file_info)) | 
| 155     return base::PLATFORM_FILE_ERROR_FAILED; | 155     return base::PLATFORM_FILE_ERROR_FAILED; | 
| 156   return base::PLATFORM_FILE_OK; | 156   return base::PLATFORM_FILE_OK; | 
| 157 } | 157 } | 
| 158 | 158 | 
| 159 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> | 159 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> | 
| 160     NativeFileUtil::CreateFileEnumerator(const base::FilePath& root_path, | 160     NativeFileUtil::CreateFileEnumerator(const base::FilePath& root_path, | 
| 161                                          bool recursive) { | 161                                          bool recursive) { | 
| 162   return make_scoped_ptr(new NativeFileEnumerator( | 162   return make_scoped_ptr(new NativeFileEnumerator( | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
| 188     return error_code; | 188     return error_code; | 
| 189   } | 189   } | 
| 190   DCHECK_NE(base::kInvalidPlatformFileValue, file); | 190   DCHECK_NE(base::kInvalidPlatformFileValue, file); | 
| 191   if (!base::TruncatePlatformFile(file, length)) | 191   if (!base::TruncatePlatformFile(file, length)) | 
| 192     error_code = base::PLATFORM_FILE_ERROR_FAILED; | 192     error_code = base::PLATFORM_FILE_ERROR_FAILED; | 
| 193   base::ClosePlatformFile(file); | 193   base::ClosePlatformFile(file); | 
| 194   return error_code; | 194   return error_code; | 
| 195 } | 195 } | 
| 196 | 196 | 
| 197 bool NativeFileUtil::PathExists(const base::FilePath& path) { | 197 bool NativeFileUtil::PathExists(const base::FilePath& path) { | 
| 198   return file_util::PathExists(path); | 198   return base::PathExists(path); | 
| 199 } | 199 } | 
| 200 | 200 | 
| 201 bool NativeFileUtil::DirectoryExists(const base::FilePath& path) { | 201 bool NativeFileUtil::DirectoryExists(const base::FilePath& path) { | 
| 202   return file_util::DirectoryExists(path); | 202   return file_util::DirectoryExists(path); | 
| 203 } | 203 } | 
| 204 | 204 | 
| 205 PlatformFileError NativeFileUtil::CopyOrMoveFile( | 205 PlatformFileError NativeFileUtil::CopyOrMoveFile( | 
| 206     const base::FilePath& src_path, | 206     const base::FilePath& src_path, | 
| 207     const base::FilePath& dest_path, | 207     const base::FilePath& dest_path, | 
| 208     bool copy) { | 208     bool copy) { | 
| (...skipping 22 matching lines...) Expand all  Loading... | 
| 231     if (base::CopyFile(src_path, dest_path)) | 231     if (base::CopyFile(src_path, dest_path)) | 
| 232       return base::PLATFORM_FILE_OK; | 232       return base::PLATFORM_FILE_OK; | 
| 233   } else { | 233   } else { | 
| 234     if (base::Move(src_path, dest_path)) | 234     if (base::Move(src_path, dest_path)) | 
| 235       return base::PLATFORM_FILE_OK; | 235       return base::PLATFORM_FILE_OK; | 
| 236   } | 236   } | 
| 237   return base::PLATFORM_FILE_ERROR_FAILED; | 237   return base::PLATFORM_FILE_ERROR_FAILED; | 
| 238 } | 238 } | 
| 239 | 239 | 
| 240 PlatformFileError NativeFileUtil::DeleteFile(const base::FilePath& path) { | 240 PlatformFileError NativeFileUtil::DeleteFile(const base::FilePath& path) { | 
| 241   if (!file_util::PathExists(path)) | 241   if (!base::PathExists(path)) | 
| 242     return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 242     return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 
| 243   if (file_util::DirectoryExists(path)) | 243   if (file_util::DirectoryExists(path)) | 
| 244     return base::PLATFORM_FILE_ERROR_NOT_A_FILE; | 244     return base::PLATFORM_FILE_ERROR_NOT_A_FILE; | 
| 245   if (!base::Delete(path, false)) | 245   if (!base::Delete(path, false)) | 
| 246     return base::PLATFORM_FILE_ERROR_FAILED; | 246     return base::PLATFORM_FILE_ERROR_FAILED; | 
| 247   return base::PLATFORM_FILE_OK; | 247   return base::PLATFORM_FILE_OK; | 
| 248 } | 248 } | 
| 249 | 249 | 
| 250 PlatformFileError NativeFileUtil::DeleteDirectory(const base::FilePath& path) { | 250 PlatformFileError NativeFileUtil::DeleteDirectory(const base::FilePath& path) { | 
| 251   if (!file_util::PathExists(path)) | 251   if (!base::PathExists(path)) | 
| 252     return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 252     return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 
| 253   if (!file_util::DirectoryExists(path)) | 253   if (!file_util::DirectoryExists(path)) | 
| 254     return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; | 254     return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; | 
| 255   if (!file_util::IsDirectoryEmpty(path)) | 255   if (!file_util::IsDirectoryEmpty(path)) | 
| 256     return base::PLATFORM_FILE_ERROR_NOT_EMPTY; | 256     return base::PLATFORM_FILE_ERROR_NOT_EMPTY; | 
| 257   if (!base::Delete(path, false)) | 257   if (!base::Delete(path, false)) | 
| 258     return base::PLATFORM_FILE_ERROR_FAILED; | 258     return base::PLATFORM_FILE_ERROR_FAILED; | 
| 259   return base::PLATFORM_FILE_OK; | 259   return base::PLATFORM_FILE_OK; | 
| 260 } | 260 } | 
| 261 | 261 | 
| 262 }  // namespace fileapi | 262 }  // namespace fileapi | 
| OLD | NEW | 
|---|