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_delete_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 DeletePath(FileSystemOperationContext* context, |
| 16 FileSystemFileUtil* file_util, |
| 17 const FileSystemPath& path, |
| 18 bool recursive) { |
| 19 if (file_util->DirectoryExists(context, path)) { |
| 20 if (!recursive) |
| 21 return file_util->DeleteSingleDirectory(context, path); |
| 22 else |
| 23 return DeleteDirectoryRecursive(context, file_util, path); |
| 24 } else { |
| 25 return file_util->DeleteFile(context, path); |
| 26 } |
| 27 } |
| 28 |
| 29 base::PlatformFileError DeleteDirectoryRecursive( |
| 30 FileSystemOperationContext* context, |
| 31 FileSystemFileUtil* file_util, |
| 32 const FileSystemPath& path) { |
| 33 |
| 34 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum( |
| 35 file_util->CreateFileEnumerator(context, path)); |
| 36 FilePath file_path_each; |
| 37 std::stack<FilePath> directories; |
| 38 while (!(file_path_each = file_enum->Next()).empty()) { |
| 39 if (file_enum->IsDirectory()) { |
| 40 directories.push(file_path_each); |
| 41 } else { |
| 42 PlatformFileError error = file_util->DeleteFile( |
| 43 context, path.WithInternalPath(file_path_each)); |
| 44 if (error != base::PLATFORM_FILE_ERROR_NOT_FOUND && |
| 45 error != base::PLATFORM_FILE_OK) |
| 46 return error; |
| 47 } |
| 48 } |
| 49 |
| 50 while (!directories.empty()) { |
| 51 PlatformFileError error = file_util->DeleteSingleDirectory( |
| 52 context, path.WithInternalPath(directories.top())); |
| 53 if (error != base::PLATFORM_FILE_ERROR_NOT_FOUND && |
| 54 error != base::PLATFORM_FILE_OK) |
| 55 return error; |
| 56 directories.pop(); |
| 57 } |
| 58 return file_util->DeleteSingleDirectory(context, path); |
| 59 } |
| 60 |
| 61 } // namespace fileapi |
OLD | NEW |