OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "services/files/directory_impl.h" | 5 #include "services/files/directory_impl.h" |
6 | 6 |
7 #include <dirent.h> | 7 #include <dirent.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <fcntl.h> | 9 #include <fcntl.h> |
10 #include <stdio.h> | 10 #include <stdio.h> |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 } | 183 } |
184 | 184 |
185 // TODO(vtl): Move the implementation to a thread pool. | 185 // TODO(vtl): Move the implementation to a thread pool. |
186 void DirectoryImpl::OpenFile(const String& path, | 186 void DirectoryImpl::OpenFile(const String& path, |
187 InterfaceRequest<File> file, | 187 InterfaceRequest<File> file, |
188 uint32_t open_flags, | 188 uint32_t open_flags, |
189 const OpenFileCallback& callback) { | 189 const OpenFileCallback& callback) { |
190 DCHECK(!path.is_null()); | 190 DCHECK(!path.is_null()); |
191 DCHECK(dir_fd_.is_valid()); | 191 DCHECK(dir_fd_.is_valid()); |
192 | 192 |
193 if (Error error = IsPathValid(path)) { | 193 Error error = IsPathValid(path); |
| 194 if (error != ERROR_OK) { |
194 callback.Run(error); | 195 callback.Run(error); |
195 return; | 196 return; |
196 } | 197 } |
197 // TODO(vtl): Make sure the path doesn't exit this directory (if appropriate). | 198 // TODO(vtl): Make sure the path doesn't exit this directory (if appropriate). |
198 // TODO(vtl): Maybe allow absolute paths? | 199 // TODO(vtl): Maybe allow absolute paths? |
199 | 200 |
200 if (Error error = ValidateOpenFlags(open_flags, false)) { | 201 error = ValidateOpenFlags(open_flags, false); |
| 202 if (error != ERROR_OK) { |
201 callback.Run(error); | 203 callback.Run(error); |
202 return; | 204 return; |
203 } | 205 } |
204 | 206 |
205 int flags = 0; | 207 int flags = 0; |
206 if ((open_flags & kOpenFlagRead)) | 208 if ((open_flags & kOpenFlagRead)) |
207 flags |= (open_flags & kOpenFlagWrite) ? O_RDWR : O_RDONLY; | 209 flags |= (open_flags & kOpenFlagWrite) ? O_RDWR : O_RDONLY; |
208 else | 210 else |
209 flags |= O_WRONLY; | 211 flags |= O_WRONLY; |
210 if ((open_flags & kOpenFlagCreate)) | 212 if ((open_flags & kOpenFlagCreate)) |
(...skipping 17 matching lines...) Expand all Loading... |
228 callback.Run(ERROR_OK); | 230 callback.Run(ERROR_OK); |
229 } | 231 } |
230 | 232 |
231 void DirectoryImpl::OpenDirectory(const String& path, | 233 void DirectoryImpl::OpenDirectory(const String& path, |
232 InterfaceRequest<Directory> directory, | 234 InterfaceRequest<Directory> directory, |
233 uint32_t open_flags, | 235 uint32_t open_flags, |
234 const OpenDirectoryCallback& callback) { | 236 const OpenDirectoryCallback& callback) { |
235 DCHECK(!path.is_null()); | 237 DCHECK(!path.is_null()); |
236 DCHECK(dir_fd_.is_valid()); | 238 DCHECK(dir_fd_.is_valid()); |
237 | 239 |
238 if (Error error = IsPathValid(path)) { | 240 Error error = IsPathValid(path); |
| 241 if (error != ERROR_OK) { |
239 callback.Run(error); | 242 callback.Run(error); |
240 return; | 243 return; |
241 } | 244 } |
242 // TODO(vtl): Make sure the path doesn't exit this directory (if appropriate). | 245 // TODO(vtl): Make sure the path doesn't exit this directory (if appropriate). |
243 // TODO(vtl): Maybe allow absolute paths? | 246 // TODO(vtl): Maybe allow absolute paths? |
244 | 247 |
245 if (Error error = ValidateOpenFlags(open_flags, false)) { | 248 error = ValidateOpenFlags(open_flags, false); |
| 249 if (error != ERROR_OK) { |
246 callback.Run(error); | 250 callback.Run(error); |
247 return; | 251 return; |
248 } | 252 } |
249 | 253 |
250 // TODO(vtl): Implement read-only (whatever that means). | 254 // TODO(vtl): Implement read-only (whatever that means). |
251 if (!(open_flags & kOpenFlagWrite)) { | 255 if (!(open_flags & kOpenFlagWrite)) { |
252 callback.Run(ERROR_UNIMPLEMENTED); | 256 callback.Run(ERROR_UNIMPLEMENTED); |
253 return; | 257 return; |
254 } | 258 } |
255 | 259 |
(...skipping 21 matching lines...) Expand all Loading... |
277 callback.Run(ERROR_OK); | 281 callback.Run(ERROR_OK); |
278 } | 282 } |
279 | 283 |
280 void DirectoryImpl::Rename(const String& path, | 284 void DirectoryImpl::Rename(const String& path, |
281 const String& new_path, | 285 const String& new_path, |
282 const RenameCallback& callback) { | 286 const RenameCallback& callback) { |
283 DCHECK(!path.is_null()); | 287 DCHECK(!path.is_null()); |
284 DCHECK(!new_path.is_null()); | 288 DCHECK(!new_path.is_null()); |
285 DCHECK(dir_fd_.is_valid()); | 289 DCHECK(dir_fd_.is_valid()); |
286 | 290 |
287 if (Error error = IsPathValid(path)) { | 291 Error error = IsPathValid(path); |
| 292 if (error != ERROR_OK) { |
288 callback.Run(error); | 293 callback.Run(error); |
289 return; | 294 return; |
290 } | 295 } |
291 if (Error error = IsPathValid(new_path)) { | 296 |
| 297 error = IsPathValid(new_path); |
| 298 if (error != ERROR_OK) { |
292 callback.Run(error); | 299 callback.Run(error); |
293 return; | 300 return; |
294 } | 301 } |
295 // TODO(vtl): See TODOs about |path| in OpenFile(). | 302 // TODO(vtl): See TODOs about |path| in OpenFile(). |
296 | 303 |
297 if (renameat(dir_fd_.get(), path.get().c_str(), dir_fd_.get(), | 304 if (renameat(dir_fd_.get(), path.get().c_str(), dir_fd_.get(), |
298 new_path.get().c_str())) { | 305 new_path.get().c_str())) { |
299 callback.Run(ErrnoToError(errno)); | 306 callback.Run(ErrnoToError(errno)); |
300 return; | 307 return; |
301 } | 308 } |
302 | 309 |
303 callback.Run(ERROR_OK); | 310 callback.Run(ERROR_OK); |
304 } | 311 } |
305 | 312 |
306 void DirectoryImpl::Delete(const String& path, | 313 void DirectoryImpl::Delete(const String& path, |
307 uint32_t delete_flags, | 314 uint32_t delete_flags, |
308 const DeleteCallback& callback) { | 315 const DeleteCallback& callback) { |
309 DCHECK(!path.is_null()); | 316 DCHECK(!path.is_null()); |
310 DCHECK(dir_fd_.is_valid()); | 317 DCHECK(dir_fd_.is_valid()); |
311 | 318 |
312 if (Error error = IsPathValid(path)) { | 319 Error error = IsPathValid(path); |
| 320 if (error != ERROR_OK) { |
313 callback.Run(error); | 321 callback.Run(error); |
314 return; | 322 return; |
315 } | 323 } |
316 // TODO(vtl): See TODOs about |path| in OpenFile(). | 324 // TODO(vtl): See TODOs about |path| in OpenFile(). |
317 | 325 |
318 if (Error error = ValidateDeleteFlags(delete_flags)) { | 326 error = ValidateDeleteFlags(delete_flags); |
| 327 if (error != ERROR_OK) { |
319 callback.Run(error); | 328 callback.Run(error); |
320 return; | 329 return; |
321 } | 330 } |
322 | 331 |
323 // TODO(vtl): Recursive not yet supported. | 332 // TODO(vtl): Recursive not yet supported. |
324 if ((delete_flags & kDeleteFlagRecursive)) { | 333 if ((delete_flags & kDeleteFlagRecursive)) { |
325 callback.Run(ERROR_UNIMPLEMENTED); | 334 callback.Run(ERROR_UNIMPLEMENTED); |
326 return; | 335 return; |
327 } | 336 } |
328 | 337 |
(...skipping 15 matching lines...) Expand all Loading... |
344 if (unlinkat(dir_fd_.get(), path.get().c_str(), AT_REMOVEDIR) == 0) { | 353 if (unlinkat(dir_fd_.get(), path.get().c_str(), AT_REMOVEDIR) == 0) { |
345 callback.Run(ERROR_OK); | 354 callback.Run(ERROR_OK); |
346 return; | 355 return; |
347 } | 356 } |
348 | 357 |
349 callback.Run(ErrnoToError(errno)); | 358 callback.Run(ErrnoToError(errno)); |
350 } | 359 } |
351 | 360 |
352 } // namespace files | 361 } // namespace files |
353 } // namespace mojo | 362 } // namespace mojo |
OLD | NEW |