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

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

Issue 9564047: Add FileUtileHelper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: handle not found case Created 8 years, 9 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
OLDNEW
(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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698