OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "webkit/fileapi/file_util_helper.h" |
| 6 |
| 7 #include "webkit/fileapi/file_system_file_util.h" |
| 8 #include "webkit/fileapi/file_system_operation_context.h" |
| 9 #include "webkit/fileapi/file_system_path.h" |
| 10 |
| 11 using base::PlatformFileError; |
| 12 |
| 13 namespace fileapi { |
| 14 |
| 15 base::PlatformFileError FileUtilHelper::Delete( |
| 16 FileSystemOperationContext* context, |
| 17 FileSystemFileUtil* file_util, |
| 18 const FileSystemPath& path, |
| 19 bool recursive) { |
| 20 if (file_util->DirectoryExists(context, path)) { |
| 21 if (!recursive) |
| 22 return file_util->DeleteSingleDirectory(context, path); |
| 23 else |
| 24 return DeleteDirectoryRecursive(context, file_util, path); |
| 25 } else { |
| 26 return file_util->DeleteFile(context, path); |
| 27 } |
| 28 } |
| 29 |
| 30 base::PlatformFileError FileUtilHelper::DeleteDirectoryRecursive( |
| 31 FileSystemOperationContext* context, |
| 32 FileSystemFileUtil* file_util, |
| 33 const FileSystemPath& path) { |
| 34 |
| 35 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum( |
| 36 file_util->CreateFileEnumerator(context, path)); |
| 37 FilePath file_path_each; |
| 38 std::stack<FilePath> directories; |
| 39 while (!(file_path_each = file_enum->Next()).empty()) { |
| 40 if (file_enum->IsDirectory()) { |
| 41 directories.push(file_path_each); |
| 42 } else { |
| 43 PlatformFileError error = file_util->DeleteFile( |
| 44 context, path.WithInternalPath(file_path_each)); |
| 45 if (error != base::PLATFORM_FILE_ERROR_NOT_FOUND && |
| 46 error != base::PLATFORM_FILE_OK) |
| 47 return error; |
| 48 } |
| 49 } |
| 50 |
| 51 while (!directories.empty()) { |
| 52 PlatformFileError error = file_util->DeleteSingleDirectory( |
| 53 context, path.WithInternalPath(directories.top())); |
| 54 if (error != base::PLATFORM_FILE_ERROR_NOT_FOUND && |
| 55 error != base::PLATFORM_FILE_OK) |
| 56 return error; |
| 57 directories.pop(); |
| 58 } |
| 59 return file_util->DeleteSingleDirectory(context, path); |
| 60 } |
| 61 |
| 62 } // namespace fileapi |
OLD | NEW |