Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: webkit/fileapi/native_file_util.cc

Issue 11960003: Cleanup: Move more recursive operation logic from FileUtilHelper to FileUtil (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/fileapi/native_file_util.h ('k') | webkit/fileapi/obfuscated_file_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/fileapi/native_file_util.h" 5 #include "webkit/fileapi/native_file_util.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "webkit/fileapi/file_system_operation_context.h" 9 #include "webkit/fileapi/file_system_operation_context.h"
10 10
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 } 195 }
196 196
197 bool NativeFileUtil::PathExists(const FilePath& path) { 197 bool NativeFileUtil::PathExists(const FilePath& path) {
198 return file_util::PathExists(path); 198 return file_util::PathExists(path);
199 } 199 }
200 200
201 bool NativeFileUtil::DirectoryExists(const FilePath& path) { 201 bool NativeFileUtil::DirectoryExists(const FilePath& path) {
202 return file_util::DirectoryExists(path); 202 return file_util::DirectoryExists(path);
203 } 203 }
204 204
205 bool NativeFileUtil::IsDirectoryEmpty(const FilePath& path) {
206 return file_util::IsDirectoryEmpty(path);
207 }
208
209 PlatformFileError NativeFileUtil::CopyOrMoveFile( 205 PlatformFileError NativeFileUtil::CopyOrMoveFile(
210 const FilePath& src_path, 206 const FilePath& src_path,
211 const FilePath& dest_path, 207 const FilePath& dest_path,
212 bool copy) { 208 bool copy) {
209 base::PlatformFileInfo info;
210 base::PlatformFileError error = NativeFileUtil::GetFileInfo(src_path, &info);
211 if (error != base::PLATFORM_FILE_OK)
212 return error;
213 if (info.is_directory)
214 return base::PLATFORM_FILE_ERROR_NOT_A_FILE;
215
216 error = NativeFileUtil::GetFileInfo(dest_path, &info);
217 if (error != base::PLATFORM_FILE_OK &&
218 error != base::PLATFORM_FILE_ERROR_NOT_FOUND)
219 return error;
220 if (info.is_directory)
221 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
222 if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND) {
223 error = NativeFileUtil::GetFileInfo(dest_path.DirName(), &info);
224 if (error != base::PLATFORM_FILE_OK)
225 return error;
226 if (!info.is_directory)
227 return base::PLATFORM_FILE_ERROR_NOT_FOUND;
228 }
229
213 if (copy) { 230 if (copy) {
214 if (file_util::CopyFile(src_path, 231 if (file_util::CopyFile(src_path, dest_path))
215 dest_path))
216 return base::PLATFORM_FILE_OK; 232 return base::PLATFORM_FILE_OK;
217 } else { 233 } else {
218 DCHECK(!file_util::DirectoryExists(src_path));
219 if (file_util::Move(src_path, dest_path)) 234 if (file_util::Move(src_path, dest_path))
220 return base::PLATFORM_FILE_OK; 235 return base::PLATFORM_FILE_OK;
221 } 236 }
222 return base::PLATFORM_FILE_ERROR_FAILED; 237 return base::PLATFORM_FILE_ERROR_FAILED;
223 } 238 }
224 239
225 PlatformFileError NativeFileUtil::DeleteFile(const FilePath& path) { 240 PlatformFileError NativeFileUtil::DeleteFile(const FilePath& path) {
226 if (!file_util::PathExists(path)) 241 if (!file_util::PathExists(path))
227 return base::PLATFORM_FILE_ERROR_NOT_FOUND; 242 return base::PLATFORM_FILE_ERROR_NOT_FOUND;
228 if (file_util::DirectoryExists(path)) 243 if (file_util::DirectoryExists(path))
229 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; 244 return base::PLATFORM_FILE_ERROR_NOT_A_FILE;
230 if (!file_util::Delete(path, false)) 245 if (!file_util::Delete(path, false))
231 return base::PLATFORM_FILE_ERROR_FAILED; 246 return base::PLATFORM_FILE_ERROR_FAILED;
232 return base::PLATFORM_FILE_OK; 247 return base::PLATFORM_FILE_OK;
233 } 248 }
234 249
235 PlatformFileError NativeFileUtil::DeleteSingleDirectory(const FilePath& path) { 250 PlatformFileError NativeFileUtil::DeleteDirectory(const FilePath& path) {
236 if (!file_util::PathExists(path)) 251 if (!file_util::PathExists(path))
237 return base::PLATFORM_FILE_ERROR_NOT_FOUND; 252 return base::PLATFORM_FILE_ERROR_NOT_FOUND;
238 if (!file_util::DirectoryExists(path)) { 253 if (!file_util::DirectoryExists(path))
239 // TODO(dmikurube): Check if this error code is appropriate.
240 return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; 254 return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY;
241 } 255 if (!file_util::IsDirectoryEmpty(path))
242 if (!file_util::IsDirectoryEmpty(path)) {
243 // TODO(dmikurube): Check if this error code is appropriate.
244 return base::PLATFORM_FILE_ERROR_NOT_EMPTY; 256 return base::PLATFORM_FILE_ERROR_NOT_EMPTY;
245 }
246 if (!file_util::Delete(path, false)) 257 if (!file_util::Delete(path, false))
247 return base::PLATFORM_FILE_ERROR_FAILED; 258 return base::PLATFORM_FILE_ERROR_FAILED;
248 return base::PLATFORM_FILE_OK; 259 return base::PLATFORM_FILE_OK;
249 } 260 }
250 261
251 } // namespace fileapi 262 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/native_file_util.h ('k') | webkit/fileapi/obfuscated_file_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698