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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 const TouchCallback& callback) { | 180 const TouchCallback& callback) { |
181 DCHECK(dir_fd_.is_valid()); | 181 DCHECK(dir_fd_.is_valid()); |
182 TouchFD(dir_fd_.get(), atime.Pass(), mtime.Pass(), callback); | 182 TouchFD(dir_fd_.get(), atime.Pass(), mtime.Pass(), callback); |
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 Error error; | |
190 DCHECK(!path.is_null()); | 191 DCHECK(!path.is_null()); |
191 DCHECK(dir_fd_.is_valid()); | 192 DCHECK(dir_fd_.is_valid()); |
192 | 193 |
193 if (Error error = IsPathValid(path)) { | 194 if ((error = IsPathValid(path)) != ERROR_OK) { |
viettrungluu
2015/09/22 22:04:58
I think I'd prefer if you just did:
Error error =
johngro
2015/09/22 22:24:12
Done.
| |
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 if ((error = ValidateOpenFlags(open_flags, false)) != ERROR_OK) { |
201 callback.Run(error); | 202 callback.Run(error); |
202 return; | 203 return; |
203 } | 204 } |
204 | 205 |
205 int flags = 0; | 206 int flags = 0; |
206 if ((open_flags & kOpenFlagRead)) | 207 if ((open_flags & kOpenFlagRead)) |
207 flags |= (open_flags & kOpenFlagWrite) ? O_RDWR : O_RDONLY; | 208 flags |= (open_flags & kOpenFlagWrite) ? O_RDWR : O_RDONLY; |
208 else | 209 else |
209 flags |= O_WRONLY; | 210 flags |= O_WRONLY; |
210 if ((open_flags & kOpenFlagCreate)) | 211 if ((open_flags & kOpenFlagCreate)) |
(...skipping 14 matching lines...) Expand all Loading... | |
225 | 226 |
226 if (file.is_pending()) | 227 if (file.is_pending()) |
227 new FileImpl(file.Pass(), file_fd.Pass()); | 228 new FileImpl(file.Pass(), file_fd.Pass()); |
228 callback.Run(ERROR_OK); | 229 callback.Run(ERROR_OK); |
229 } | 230 } |
230 | 231 |
231 void DirectoryImpl::OpenDirectory(const String& path, | 232 void DirectoryImpl::OpenDirectory(const String& path, |
232 InterfaceRequest<Directory> directory, | 233 InterfaceRequest<Directory> directory, |
233 uint32_t open_flags, | 234 uint32_t open_flags, |
234 const OpenDirectoryCallback& callback) { | 235 const OpenDirectoryCallback& callback) { |
236 Error error; | |
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 if ((error = IsPathValid(path)) != ERROR_OK) { |
239 callback.Run(error); | 241 callback.Run(error); |
240 return; | 242 return; |
241 } | 243 } |
242 // TODO(vtl): Make sure the path doesn't exit this directory (if appropriate). | 244 // TODO(vtl): Make sure the path doesn't exit this directory (if appropriate). |
243 // TODO(vtl): Maybe allow absolute paths? | 245 // TODO(vtl): Maybe allow absolute paths? |
244 | 246 |
245 if (Error error = ValidateOpenFlags(open_flags, false)) { | 247 if ((error = ValidateOpenFlags(open_flags, false)) != ERROR_OK) { |
246 callback.Run(error); | 248 callback.Run(error); |
247 return; | 249 return; |
248 } | 250 } |
249 | 251 |
250 // TODO(vtl): Implement read-only (whatever that means). | 252 // TODO(vtl): Implement read-only (whatever that means). |
251 if (!(open_flags & kOpenFlagWrite)) { | 253 if (!(open_flags & kOpenFlagWrite)) { |
252 callback.Run(ERROR_UNIMPLEMENTED); | 254 callback.Run(ERROR_UNIMPLEMENTED); |
253 return; | 255 return; |
254 } | 256 } |
255 | 257 |
(...skipping 17 matching lines...) Expand all Loading... | |
273 } | 275 } |
274 | 276 |
275 if (directory.is_pending()) | 277 if (directory.is_pending()) |
276 new DirectoryImpl(directory.Pass(), new_dir_fd.Pass(), nullptr); | 278 new DirectoryImpl(directory.Pass(), new_dir_fd.Pass(), nullptr); |
277 callback.Run(ERROR_OK); | 279 callback.Run(ERROR_OK); |
278 } | 280 } |
279 | 281 |
280 void DirectoryImpl::Rename(const String& path, | 282 void DirectoryImpl::Rename(const String& path, |
281 const String& new_path, | 283 const String& new_path, |
282 const RenameCallback& callback) { | 284 const RenameCallback& callback) { |
285 Error error; | |
283 DCHECK(!path.is_null()); | 286 DCHECK(!path.is_null()); |
284 DCHECK(!new_path.is_null()); | 287 DCHECK(!new_path.is_null()); |
285 DCHECK(dir_fd_.is_valid()); | 288 DCHECK(dir_fd_.is_valid()); |
286 | 289 |
287 if (Error error = IsPathValid(path)) { | 290 if ((error = IsPathValid(path)) != ERROR_OK) { |
288 callback.Run(error); | 291 callback.Run(error); |
289 return; | 292 return; |
290 } | 293 } |
291 if (Error error = IsPathValid(new_path)) { | 294 if ((error = IsPathValid(new_path)) != ERROR_OK) { |
292 callback.Run(error); | 295 callback.Run(error); |
293 return; | 296 return; |
294 } | 297 } |
295 // TODO(vtl): See TODOs about |path| in OpenFile(). | 298 // TODO(vtl): See TODOs about |path| in OpenFile(). |
296 | 299 |
297 if (renameat(dir_fd_.get(), path.get().c_str(), dir_fd_.get(), | 300 if (renameat(dir_fd_.get(), path.get().c_str(), dir_fd_.get(), |
298 new_path.get().c_str())) { | 301 new_path.get().c_str())) { |
299 callback.Run(ErrnoToError(errno)); | 302 callback.Run(ErrnoToError(errno)); |
300 return; | 303 return; |
301 } | 304 } |
302 | 305 |
303 callback.Run(ERROR_OK); | 306 callback.Run(ERROR_OK); |
304 } | 307 } |
305 | 308 |
306 void DirectoryImpl::Delete(const String& path, | 309 void DirectoryImpl::Delete(const String& path, |
307 uint32_t delete_flags, | 310 uint32_t delete_flags, |
308 const DeleteCallback& callback) { | 311 const DeleteCallback& callback) { |
312 Error error; | |
309 DCHECK(!path.is_null()); | 313 DCHECK(!path.is_null()); |
310 DCHECK(dir_fd_.is_valid()); | 314 DCHECK(dir_fd_.is_valid()); |
311 | 315 |
312 if (Error error = IsPathValid(path)) { | 316 if ((error = IsPathValid(path)) != ERROR_OK) { |
313 callback.Run(error); | 317 callback.Run(error); |
314 return; | 318 return; |
315 } | 319 } |
316 // TODO(vtl): See TODOs about |path| in OpenFile(). | 320 // TODO(vtl): See TODOs about |path| in OpenFile(). |
317 | 321 |
318 if (Error error = ValidateDeleteFlags(delete_flags)) { | 322 if ((error = ValidateDeleteFlags(delete_flags)) != ERROR_OK) { |
319 callback.Run(error); | 323 callback.Run(error); |
320 return; | 324 return; |
321 } | 325 } |
322 | 326 |
323 // TODO(vtl): Recursive not yet supported. | 327 // TODO(vtl): Recursive not yet supported. |
324 if ((delete_flags & kDeleteFlagRecursive)) { | 328 if ((delete_flags & kDeleteFlagRecursive)) { |
325 callback.Run(ERROR_UNIMPLEMENTED); | 329 callback.Run(ERROR_UNIMPLEMENTED); |
326 return; | 330 return; |
327 } | 331 } |
328 | 332 |
(...skipping 15 matching lines...) Expand all Loading... | |
344 if (unlinkat(dir_fd_.get(), path.get().c_str(), AT_REMOVEDIR) == 0) { | 348 if (unlinkat(dir_fd_.get(), path.get().c_str(), AT_REMOVEDIR) == 0) { |
345 callback.Run(ERROR_OK); | 349 callback.Run(ERROR_OK); |
346 return; | 350 return; |
347 } | 351 } |
348 | 352 |
349 callback.Run(ErrnoToError(errno)); | 353 callback.Run(ErrnoToError(errno)); |
350 } | 354 } |
351 | 355 |
352 } // namespace files | 356 } // namespace files |
353 } // namespace mojo | 357 } // namespace mojo |
OLD | NEW |