OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "webkit/fileapi/cross_file_util_helper.h" | 5 #include "webkit/fileapi/cross_file_util_helper.h" |
6 | 6 |
7 #include "webkit/fileapi/file_system_file_util.h" | 7 #include "webkit/fileapi/file_system_file_util.h" |
8 #include "webkit/fileapi/file_system_operation_context.h" | 8 #include "webkit/fileapi/file_system_operation_context.h" |
9 #include "webkit/fileapi/file_system_path.h" | 9 #include "webkit/fileapi/file_system_path.h" |
| 10 #include "webkit/fileapi/file_util_helper.h" |
10 | 11 |
11 using base::PlatformFileError; | 12 using base::PlatformFileError; |
12 | 13 |
13 namespace fileapi { | 14 namespace fileapi { |
14 | 15 |
15 CrossFileUtilHelper::CrossFileUtilHelper( | 16 CrossFileUtilHelper::CrossFileUtilHelper( |
16 FileSystemOperationContext* context, | 17 FileSystemOperationContext* context, |
17 FileSystemFileUtil* src_util, | 18 FileSystemFileUtil* src_util, |
18 FileSystemFileUtil* dest_util, | 19 FileSystemFileUtil* dest_util, |
19 const FileSystemPath& src_path, | 20 const FileSystemPath& src_path, |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 if (same_file_system && (src_root_path_.internal_path() == | 77 if (same_file_system && (src_root_path_.internal_path() == |
77 dest_root_path_.internal_path())) | 78 dest_root_path_.internal_path())) |
78 return base::PLATFORM_FILE_ERROR_EXISTS; | 79 return base::PLATFORM_FILE_ERROR_EXISTS; |
79 | 80 |
80 if (dest_is_directory) { | 81 if (dest_is_directory) { |
81 // It is an error to copy/move an entry to a non-empty directory. | 82 // It is an error to copy/move an entry to a non-empty directory. |
82 // Otherwise the copy/move attempt must overwrite the destination, but | 83 // Otherwise the copy/move attempt must overwrite the destination, but |
83 // the file_util's Copy or Move method doesn't perform overwrite | 84 // the file_util's Copy or Move method doesn't perform overwrite |
84 // on all platforms, so we delete the destination directory here. | 85 // on all platforms, so we delete the destination directory here. |
85 if (base::PLATFORM_FILE_OK != | 86 if (base::PLATFORM_FILE_OK != |
86 dest_util_->Delete(context_, dest_root_path_, false /* recursive */)) { | 87 dest_util_->DeleteSingleDirectory(context_, dest_root_path_)) { |
87 if (!dest_util_->IsDirectoryEmpty(context_, dest_root_path_)) | 88 if (!dest_util_->IsDirectoryEmpty(context_, dest_root_path_)) |
88 return base::PLATFORM_FILE_ERROR_NOT_EMPTY; | 89 return base::PLATFORM_FILE_ERROR_NOT_EMPTY; |
89 return base::PLATFORM_FILE_ERROR_FAILED; | 90 return base::PLATFORM_FILE_ERROR_FAILED; |
90 } | 91 } |
91 } | 92 } |
92 return base::PLATFORM_FILE_OK; | 93 return base::PLATFORM_FILE_OK; |
93 } | 94 } |
94 | 95 |
95 bool CrossFileUtilHelper::ParentExists( | 96 bool CrossFileUtilHelper::ParentExists( |
96 const FileSystemPath& path, FileSystemFileUtil* file_util) { | 97 const FileSystemPath& path, FileSystemFileUtil* file_util) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 } else { | 136 } else { |
136 PlatformFileError error = CopyOrMoveFile( | 137 PlatformFileError error = CopyOrMoveFile( |
137 src_path.WithInternalPath(src_file_path_each), | 138 src_path.WithInternalPath(src_file_path_each), |
138 dest_path.WithInternalPath(dest_file_path_each)); | 139 dest_path.WithInternalPath(dest_file_path_each)); |
139 if (error != base::PLATFORM_FILE_OK) | 140 if (error != base::PLATFORM_FILE_OK) |
140 return error; | 141 return error; |
141 } | 142 } |
142 } | 143 } |
143 | 144 |
144 if (operation_ == OPERATION_MOVE) { | 145 if (operation_ == OPERATION_MOVE) { |
145 PlatformFileError error = src_util_->Delete(context_, src_path, true); | 146 PlatformFileError error = |
| 147 FileUtilHelper::Delete(context_, src_util_, |
| 148 src_path, true /* recursive */); |
146 if (error != base::PLATFORM_FILE_OK) | 149 if (error != base::PLATFORM_FILE_OK) |
147 return error; | 150 return error; |
148 } | 151 } |
149 | 152 |
150 return base::PLATFORM_FILE_OK; | 153 return base::PLATFORM_FILE_OK; |
151 } | 154 } |
152 | 155 |
153 PlatformFileError CrossFileUtilHelper::CopyOrMoveFile( | 156 PlatformFileError CrossFileUtilHelper::CopyOrMoveFile( |
154 const FileSystemPath& src_path, | 157 const FileSystemPath& src_path, |
155 const FileSystemPath& dest_path) { | 158 const FileSystemPath& dest_path) { |
(...skipping 18 matching lines...) Expand all Loading... |
174 // to perform limited cross-FileSystemFileUtil copy/move. | 177 // to perform limited cross-FileSystemFileUtil copy/move. |
175 error = dest_util_->CopyInForeignFile( | 178 error = dest_util_->CopyInForeignFile( |
176 context_, src_path.WithInternalPath(platform_file_path), dest_path); | 179 context_, src_path.WithInternalPath(platform_file_path), dest_path); |
177 | 180 |
178 if (operation_ == OPERATION_COPY || error != base::PLATFORM_FILE_OK) | 181 if (operation_ == OPERATION_COPY || error != base::PLATFORM_FILE_OK) |
179 return error; | 182 return error; |
180 return src_util_->DeleteFile(context_, src_path); | 183 return src_util_->DeleteFile(context_, src_path); |
181 } | 184 } |
182 | 185 |
183 } // namespace fileapi | 186 } // namespace fileapi |
OLD | NEW |