diff options
author | tzik@chromium.org <tzik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-03 02:09:07 +0000 |
---|---|---|
committer | tzik@chromium.org <tzik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-03 02:09:07 +0000 |
commit | aa437fa87e3b4d0eadf5562fa3ed7e4b3e4a7811 (patch) | |
tree | 308c34b414a160f8dabf42bb60a712232d3bdf42 /webkit/fileapi/file_util_helper.cc | |
parent | c3ebc3261f1de891dd4b791084743590f7dc3b78 (diff) | |
download | chromium_src-aa437fa87e3b4d0eadf5562fa3ed7e4b3e4a7811.zip chromium_src-aa437fa87e3b4d0eadf5562fa3ed7e4b3e4a7811.tar.gz chromium_src-aa437fa87e3b4d0eadf5562fa3ed7e4b3e4a7811.tar.bz2 |
Add FileUtileHelper and split out FileSystemFileUtil::Delete
BUG=114732
TEST='existing tests'
Review URL: http://codereview.chromium.org/9564047
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124824 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi/file_util_helper.cc')
-rw-r--r-- | webkit/fileapi/file_util_helper.cc | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/webkit/fileapi/file_util_helper.cc b/webkit/fileapi/file_util_helper.cc new file mode 100644 index 0000000..46163ea --- /dev/null +++ b/webkit/fileapi/file_util_helper.cc @@ -0,0 +1,62 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "webkit/fileapi/file_util_helper.h" + +#include "webkit/fileapi/file_system_file_util.h" +#include "webkit/fileapi/file_system_operation_context.h" +#include "webkit/fileapi/file_system_path.h" + +using base::PlatformFileError; + +namespace fileapi { + +base::PlatformFileError FileUtilHelper::Delete( + FileSystemOperationContext* context, + FileSystemFileUtil* file_util, + const FileSystemPath& path, + bool recursive) { + if (file_util->DirectoryExists(context, path)) { + if (!recursive) + return file_util->DeleteSingleDirectory(context, path); + else + return DeleteDirectoryRecursive(context, file_util, path); + } else { + return file_util->DeleteFile(context, path); + } +} + +base::PlatformFileError FileUtilHelper::DeleteDirectoryRecursive( + FileSystemOperationContext* context, + FileSystemFileUtil* file_util, + const FileSystemPath& path) { + + scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum( + file_util->CreateFileEnumerator(context, path)); + FilePath file_path_each; + std::stack<FilePath> directories; + while (!(file_path_each = file_enum->Next()).empty()) { + if (file_enum->IsDirectory()) { + directories.push(file_path_each); + } else { + PlatformFileError error = file_util->DeleteFile( + context, path.WithInternalPath(file_path_each)); + if (error != base::PLATFORM_FILE_ERROR_NOT_FOUND && + error != base::PLATFORM_FILE_OK) + return error; + } + } + + while (!directories.empty()) { + PlatformFileError error = file_util->DeleteSingleDirectory( + context, path.WithInternalPath(directories.top())); + if (error != base::PLATFORM_FILE_ERROR_NOT_FOUND && + error != base::PLATFORM_FILE_OK) + return error; + directories.pop(); + } + return file_util->DeleteSingleDirectory(context, path); +} + +} // namespace fileapi |