From 3bf73d5ec779ce14a04a00d24d71a038fd954832 Mon Sep 17 00:00:00 2001 From: "kinuko@chromium.org" Date: Mon, 7 Mar 2011 22:57:58 +0000 Subject: Revive FileAPI's recursive CreateDirectory. PPAPI's MakeDirectoryIncludingAncestors() (ppapi/cpp/dev/file_ref_dev.cc) uses recursive CreateDirectory. BUG=74841 TEST=none Review URL: http://codereview.chromium.org/6627028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77204 0039d316-1c4b-4281-b951-d872f2087c98 --- webkit/fileapi/file_system_file_util.cc | 12 ++++++++---- webkit/fileapi/file_system_file_util.h | 3 ++- webkit/fileapi/file_system_file_util_proxy.cc | 10 +++++++--- webkit/fileapi/file_system_file_util_proxy.h | 1 + webkit/fileapi/file_system_operation.cc | 5 ++--- webkit/fileapi/file_system_operation.h | 2 +- 6 files changed, 21 insertions(+), 12 deletions(-) (limited to 'webkit/fileapi') diff --git a/webkit/fileapi/file_system_file_util.cc b/webkit/fileapi/file_system_file_util.cc index 52f2c70..c5e8fef 100644 --- a/webkit/fileapi/file_system_file_util.cc +++ b/webkit/fileapi/file_system_file_util.cc @@ -157,16 +157,20 @@ PlatformFileError FileSystemFileUtil::ReadDirectory( PlatformFileError FileSystemFileUtil::CreateDirectory( FileSystemOperationContext* unused, const FilePath& file_path, - bool exclusive) { - bool path_exists = file_util::PathExists(file_path); - if (!file_util::PathExists(file_path.DirName())) - return base::PLATFORM_FILE_ERROR_NOT_FOUND; + bool exclusive, + bool recursive) { // If parent dir of file doesn't exist. + if (!recursive && !file_util::PathExists(file_path.DirName())) + return base::PLATFORM_FILE_ERROR_NOT_FOUND; + + bool path_exists = file_util::PathExists(file_path); if (exclusive && path_exists) return base::PLATFORM_FILE_ERROR_EXISTS; + // If file exists at the path. if (path_exists && !file_util::DirectoryExists(file_path)) return base::PLATFORM_FILE_ERROR_EXISTS; + if (!file_util::CreateDirectory(file_path)) return base::PLATFORM_FILE_ERROR_FAILED; return base::PLATFORM_FILE_OK; diff --git a/webkit/fileapi/file_system_file_util.h b/webkit/fileapi/file_system_file_util.h index 433c0bc..9b02a44 100644 --- a/webkit/fileapi/file_system_file_util.h +++ b/webkit/fileapi/file_system_file_util.h @@ -80,7 +80,8 @@ class FileSystemFileUtil { virtual PlatformFileError CreateDirectory( FileSystemOperationContext* context, const FilePath& file_path, - bool exclusive); + bool exclusive, + bool recursive); // Copies a file or a directory from |src_file_path| to |dest_file_path| // Error cases: diff --git a/webkit/fileapi/file_system_file_util_proxy.cc b/webkit/fileapi/file_system_file_util_proxy.cc index 3b14e16..faf3d4a 100644 --- a/webkit/fileapi/file_system_file_util_proxy.cc +++ b/webkit/fileapi/file_system_file_util_proxy.cc @@ -258,22 +258,25 @@ class RelayCreateDirectory : public RelayWithStatusCallback { const fileapi::FileSystemOperationContext& context, const FilePath& file_path, bool exclusive, + bool recursive, fileapi::FileSystemFileUtilProxy::StatusCallback* callback) : RelayWithStatusCallback(context, callback), file_path_(file_path), - exclusive_(exclusive) { + exclusive_(exclusive), + recursive_(recursive) { } protected: virtual void RunWork() { set_error_code( file_system_file_util()->CreateDirectory( - context(), file_path_, exclusive_)); + context(), file_path_, exclusive_, recursive_)); } private: FilePath file_path_; bool exclusive_; + bool recursive_; }; class RelayCopy : public RelayWithStatusCallback { @@ -460,9 +463,10 @@ bool FileSystemFileUtilProxy::CreateDirectory( scoped_refptr message_loop_proxy, const FilePath& file_path, bool exclusive, + bool recursive, StatusCallback* callback) { return Start(FROM_HERE, message_loop_proxy, new RelayCreateDirectory( - context, file_path, exclusive, callback)); + context, file_path, exclusive, recursive, callback)); } // static diff --git a/webkit/fileapi/file_system_file_util_proxy.h b/webkit/fileapi/file_system_file_util_proxy.h index 0f10507..525f9c8 100644 --- a/webkit/fileapi/file_system_file_util_proxy.h +++ b/webkit/fileapi/file_system_file_util_proxy.h @@ -89,6 +89,7 @@ class FileSystemFileUtilProxy { scoped_refptr message_loop_proxy, const FilePath& file_path, bool exclusive, + bool recursive, StatusCallback* callback); // Copies a file or a directory from |src_file_path| to |dest_file_path| diff --git a/webkit/fileapi/file_system_operation.cc b/webkit/fileapi/file_system_operation.cc index ec3ea7e..0b800ba 100644 --- a/webkit/fileapi/file_system_operation.cc +++ b/webkit/fileapi/file_system_operation.cc @@ -71,12 +71,11 @@ void FileSystemOperation::CreateFile(const FilePath& path, void FileSystemOperation::CreateDirectory(const FilePath& path, bool exclusive, - bool unused) { + bool recursive) { #ifndef NDEBUG DCHECK(kOperationNone == pending_operation_); pending_operation_ = kOperationCreateDirectory; #endif - DCHECK(!unused); if (!VerifyFileSystemPathForWrite(path, true /* create */)) { delete this; @@ -84,7 +83,7 @@ void FileSystemOperation::CreateDirectory(const FilePath& path, } FileSystemFileUtilProxy::CreateDirectory( file_system_operation_context_, - proxy_, path, exclusive, callback_factory_.NewCallback( + proxy_, path, exclusive, recursive, callback_factory_.NewCallback( &FileSystemOperation::DidFinishFileOperation)); } diff --git a/webkit/fileapi/file_system_operation.h b/webkit/fileapi/file_system_operation.h index 9fa2db4..a7ee52b 100644 --- a/webkit/fileapi/file_system_operation.h +++ b/webkit/fileapi/file_system_operation.h @@ -56,7 +56,7 @@ class FileSystemOperation { bool exclusive); void CreateDirectory(const FilePath& path, bool exclusive, - bool unused); + bool recursive); void Copy(const FilePath& src_path, const FilePath& dest_path); void Move(const FilePath& src_path, -- cgit v1.1