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 FileUtilDeleteHelper::FileUtilDeleteHelper( | |
16 FileSystemOperationContext* context, | |
17 FileSystemFileUtil* file_util) | |
18 : context_(context), | |
19 file_util_(file_util) { | |
20 } | |
21 | |
22 FileUtilDeleteHelper::~FileUtilDeleteHelper() { | |
23 } | |
24 | |
25 base::PlatformFileError FileUtilDeleteHelper::DoWork(const FileSystemPath& path, | |
26 bool recursive) { | |
27 if (file_util_->DirectoryExists(context_, path)) { | |
28 if (!recursive) | |
29 return file_util_->DeleteSingleDirectory(context_, path); | |
30 else | |
31 return DeleteDirectoryRecursive(path); | |
32 } else { | |
33 return file_util_->DeleteFile(context_, path); | |
34 } | |
35 } | |
36 | |
37 PlatformFileError FileUtilDeleteHelper::DeleteDirectoryRecursive( | |
38 const FileSystemPath& path) { | |
39 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum( | |
40 file_util_->CreateFileEnumerator(context_, path)); | |
41 FilePath file_path_each; | |
42 std::stack<FilePath> directories; | |
43 while (!(file_path_each = file_enum->Next()).empty()) { | |
44 if (file_enum->IsDirectory()) { | |
45 directories.push(file_path_each); | |
46 } else { | |
47 PlatformFileError error = file_util_->DeleteFile( | |
48 context_, path.WithInternalPath(file_path_each)); | |
49 if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND) | |
50 return base::PLATFORM_FILE_ERROR_FAILED; | |
kinuko
2012/03/02 05:25:16
It makes me wonder we should just let it go here..
tzik
2012/03/02 19:09:09
Seems right. No test require it.
| |
51 else if (error != base::PLATFORM_FILE_OK) | |
52 return error; | |
53 } | |
54 } | |
55 | |
56 while (!directories.empty()) { | |
57 PlatformFileError error = file_util_->DeleteSingleDirectory( | |
58 context_, path.WithInternalPath(directories.top())); | |
59 if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND) | |
60 return base::PLATFORM_FILE_ERROR_FAILED; | |
61 else if (error != base::PLATFORM_FILE_OK) | |
62 return error; | |
63 directories.pop(); | |
64 } | |
65 return file_util_->DeleteSingleDirectory(context_, path); | |
66 } | |
67 | |
68 } // namespace fileapi | |
OLD | NEW |