1 // Copyright 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/fuchsia/file_utils.h"
8 #include <lib/fdio/fd.h>
10 #include <sys/types.h>
15 #include "base/files/scoped_file.h"
16 #include "base/fuchsia/fuchsia_logging.h"
17 #include "base/macros.h"
22 const char kPersistedDataDirectoryPath[] = "/data";
23 const char kServiceDirectoryPath[] = "/svc";
24 const char kPackageRootDirectoryPath[] = "/pkg";
26 fidl::InterfaceHandle<::fuchsia::io::Directory> OpenDirectory(
27 const base::FilePath& path) {
28 ScopedFD fd(open(path.value().c_str(), O_DIRECTORY | O_RDONLY));
30 DPLOG(ERROR) << "Failed to open " << path;
31 return fidl::InterfaceHandle<::fuchsia::io::Directory>();
36 fdio_fd_transfer(fd.get(), channel.reset_and_get_address());
37 if (status != ZX_ERR_UNAVAILABLE)
38 ignore_result(fd.release());
39 if (status != ZX_OK) {
40 ZX_DLOG(ERROR, status) << "fdio_fd_transfer";
41 return fidl::InterfaceHandle<::fuchsia::io::Directory>();
44 return fidl::InterfaceHandle<::fuchsia::io::Directory>(std::move(channel));
47 } // namespace fuchsia