| 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 "files/public/c/lib/directory_wrapper.h" | 5 #include "files/public/c/lib/directory_wrapper.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 | 8 |
| 9 #include "files/public/c/lib/errno_impl.h" | 9 #include "files/public/c/lib/errno_impl.h" |
| 10 #include "files/public/c/lib/file_fd_impl.h" | 10 #include "files/public/c/lib/file_fd_impl.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 // TODO(vtl): What should we do we open flags we don't support? And invalid | 67 // TODO(vtl): What should we do we open flags we don't support? And invalid |
| 68 // flags? | 68 // flags? |
| 69 | 69 |
| 70 // TODO(vtl): We currently totally ignore |mode|; maybe we should do something | 70 // TODO(vtl): We currently totally ignore |mode|; maybe we should do something |
| 71 // with it? | 71 // with it? |
| 72 | 72 |
| 73 mojo::files::FilePtr file; | 73 mojo::files::FilePtr file; |
| 74 mojo::files::Error error = mojo::files::ERROR_INTERNAL; | 74 mojo::files::Error error = mojo::files::ERROR_INTERNAL; |
| 75 directory_->OpenFile(path, mojo::GetProxy(&file), mojo_open_flags, | 75 directory_->OpenFile(path, mojo::GetProxy(&file), mojo_open_flags, |
| 76 Capture(&error)); | 76 Capture(&error)); |
| 77 if (!directory_.WaitForIncomingMethodCall()) { | 77 if (!directory_.WaitForIncomingResponse()) { |
| 78 // This may be somewhat surprising. The implication is that the CWD is | 78 // This may be somewhat surprising. The implication is that the CWD is |
| 79 // stale, which may be a little strange. | 79 // stale, which may be a little strange. |
| 80 errno_setter.Set(ESTALE); | 80 errno_setter.Set(ESTALE); |
| 81 return nullptr; | 81 return nullptr; |
| 82 } | 82 } |
| 83 if (!errno_setter.Set(ErrorToErrno(error))) | 83 if (!errno_setter.Set(ErrorToErrno(error))) |
| 84 return nullptr; | 84 return nullptr; |
| 85 // C++11, why don't you have make_unique? | 85 // C++11, why don't you have make_unique? |
| 86 return std::unique_ptr<FDImpl>(new FileFDImpl(errno_impl_, file.Pass())); | 86 return std::unique_ptr<FDImpl>(new FileFDImpl(errno_impl_, file.Pass())); |
| 87 } | 87 } |
| 88 | 88 |
| 89 bool DirectoryWrapper::Chdir(const char* path) { | 89 bool DirectoryWrapper::Chdir(const char* path) { |
| 90 ErrnoImpl::Setter errno_setter(errno_impl_); | 90 ErrnoImpl::Setter errno_setter(errno_impl_); |
| 91 | 91 |
| 92 if (!path) | 92 if (!path) |
| 93 return errno_setter.Set(EFAULT); | 93 return errno_setter.Set(EFAULT); |
| 94 | 94 |
| 95 mojo::files::DirectoryPtr new_directory; | 95 mojo::files::DirectoryPtr new_directory; |
| 96 mojo::files::Error error = mojo::files::ERROR_INTERNAL; | 96 mojo::files::Error error = mojo::files::ERROR_INTERNAL; |
| 97 directory_->OpenDirectory( | 97 directory_->OpenDirectory( |
| 98 path, mojo::GetProxy(&new_directory), | 98 path, mojo::GetProxy(&new_directory), |
| 99 mojo::files::kOpenFlagRead | mojo::files::kOpenFlagWrite, | 99 mojo::files::kOpenFlagRead | mojo::files::kOpenFlagWrite, |
| 100 Capture(&error)); | 100 Capture(&error)); |
| 101 if (!directory_.WaitForIncomingMethodCall()) { | 101 if (!directory_.WaitForIncomingResponse()) { |
| 102 // This may be somewhat surprising. The implication is that the CWD is | 102 // This may be somewhat surprising. The implication is that the CWD is |
| 103 // stale, which may be a little strange. | 103 // stale, which may be a little strange. |
| 104 return errno_setter.Set(ESTALE); | 104 return errno_setter.Set(ESTALE); |
| 105 } | 105 } |
| 106 if (!errno_setter.Set(ErrorToErrno(error))) | 106 if (!errno_setter.Set(ErrorToErrno(error))) |
| 107 return false; | 107 return false; |
| 108 directory_ = new_directory.Pass(); | 108 directory_ = new_directory.Pass(); |
| 109 return true; | 109 return true; |
| 110 } | 110 } |
| 111 | 111 |
| 112 } // namespace mojio | 112 } // namespace mojio |
| OLD | NEW |