Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions base/cvd/cuttlefish/common/libs/utils/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ cf_cc_library(
"//cuttlefish/files:file_device_id",
"//cuttlefish/files:file_exists",
"//cuttlefish/files:link_or_copy",
"//cuttlefish/posix:realpath",
"//cuttlefish/posix:rename",
"//cuttlefish/posix:strerror",
"//cuttlefish/result",
Expand Down
14 changes: 1 addition & 13 deletions base/cvd/cuttlefish/common/libs/utils/files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include <sys/stat.h>
#include <unistd.h>

#include <array>
#include <chrono>
#include <fstream>
#include <ios>
Expand Down Expand Up @@ -59,6 +58,7 @@
#include "cuttlefish/files/file_device_id.h"
#include "cuttlefish/files/file_exists.h"
#include "cuttlefish/files/link_or_copy.h"
#include "cuttlefish/posix/realpath.h"
#include "cuttlefish/posix/rename.h"
#include "cuttlefish/posix/strerror.h"
#include "cuttlefish/result/result.h"
Expand Down Expand Up @@ -222,18 +222,6 @@ std::string AbsolutePath(std::string_view path) {
return absl::StrCat(*real_cwd, "/", path);
}

Result<std::string> RealPath(const std::string& path) {
// NOLINTNEXTLINE(misc-include-cleaner): <limits.h>
std::array<char, PATH_MAX> buffer{};
char* res;
do {
res = realpath(path.c_str(), buffer.data());
} while (res == nullptr && errno == EINTR);
CF_EXPECTF(res != nullptr, "Could not get real path for path \"{}\": {}",
path, StrError(errno));
return std::string(buffer.data());
}

off_t FileSize(const std::string& path) {
struct stat st{};
if (stat(path.c_str(), &st) == -1) {
Expand Down
2 changes: 0 additions & 2 deletions base/cvd/cuttlefish/common/libs/utils/files.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ Result<uid_t> FileOwner(const std::string& path);
// argument.
std::string AbsolutePath(std::string_view path);

Result<std::string> RealPath(const std::string& path);

std::string CurrentDirectory();

struct FileSizes {
Expand Down
1 change: 1 addition & 0 deletions base/cvd/cuttlefish/host/commands/cvd/cli/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ cf_cc_library(
"//cuttlefish/host/commands/cvd/instances:instance_manager",
"//cuttlefish/host/commands/cvd/instances/lock",
"//cuttlefish/host/commands/cvd/utils",
"//cuttlefish/posix:realpath",
"//cuttlefish/posix:strerror",
"//cuttlefish/posix:symlink",
"//cuttlefish/result",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#include "cuttlefish/host/commands/cvd/instances/instance_manager.h"
#include "cuttlefish/host/commands/cvd/instances/local_instance_group.h"
#include "cuttlefish/host/commands/cvd/utils/common.h"
#include "cuttlefish/posix/realpath.h"
#include "cuttlefish/posix/strerror.h"
#include "cuttlefish/posix/symlink.h"
#include "cuttlefish/result/result.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ cf_cc_library(
"//cuttlefish/common/libs/utils:files",
"//cuttlefish/files:directory_exists",
"//cuttlefish/files:file_exists",
"//cuttlefish/posix:realpath",
"//cuttlefish/result",
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@

#include "cuttlefish/host/commands/cvd/instances/config_path.h"

#include <string>

#include "cuttlefish/common/libs/utils/files.h"
#include "cuttlefish/files/directory_exists.h"
#include "cuttlefish/files/file_exists.h"
#include "cuttlefish/posix/realpath.h"

namespace cuttlefish {

Expand Down
1 change: 1 addition & 0 deletions base/cvd/cuttlefish/host/libs/command_util/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ cf_cc_library(
"//cuttlefish/host/libs/config:config_instance_derived",
"//cuttlefish/host/libs/config:cuttlefish_config",
"//cuttlefish/posix:readlink",
"//cuttlefish/posix:realpath",
"//cuttlefish/posix:strerror",
"//cuttlefish/posix:symlink",
"//cuttlefish/result",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "cuttlefish/files/directory_exists.h"
#include "cuttlefish/files/file_exists.h"
#include "cuttlefish/posix/readlink.h"
#include "cuttlefish/posix/realpath.h"
#include "cuttlefish/posix/symlink.h"
#include "cuttlefish/result/result.h"

Expand Down
4 changes: 1 addition & 3 deletions base/cvd/cuttlefish/host/libs/config/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,11 @@ cf_cc_library(
name = "fetcher_configs",
srcs = ["fetcher_configs.cc"],
hdrs = ["fetcher_configs.h"],
depend_on_what_you_use_enabled = False,
deps = [
"//cuttlefish/common/libs/utils:files",
"//cuttlefish/files:file_exists",
"//cuttlefish/host/libs/config:fetcher_config",
"//cuttlefish/posix:realpath",
"//cuttlefish/result",
"//libbase",
"@abseil-cpp//absl/log",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/types:span",
Expand Down
2 changes: 1 addition & 1 deletion base/cvd/cuttlefish/host/libs/config/fetcher_configs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
#include "absl/strings/str_cat.h"
#include "absl/types/span.h"

#include "cuttlefish/common/libs/utils/files.h"
#include "cuttlefish/files/file_exists.h"
#include "cuttlefish/host/libs/config/fetcher_config.h"
#include "cuttlefish/posix/realpath.h"
#include "cuttlefish/result/result.h"

namespace cuttlefish {
Expand Down
2 changes: 1 addition & 1 deletion base/cvd/cuttlefish/host/libs/image_aggregator/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ cf_cc_library(
hdrs = ["sparse_image.h"],
deps = [
"//cuttlefish/common/libs/fs",
"//cuttlefish/common/libs/utils:files",
"//cuttlefish/host/libs/config:known_paths",
"//cuttlefish/host/libs/image_aggregator:disk_image",
"//cuttlefish/posix:realpath",
"//cuttlefish/posix:rename",
"//cuttlefish/process:execute",
"//cuttlefish/result",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
#include "sparse/sparse.h"

#include "cuttlefish/common/libs/fs/shared_fd.h"
#include "cuttlefish/common/libs/utils/files.h"
#include "cuttlefish/host/libs/config/known_paths.h"
#include "cuttlefish/posix/realpath.h"
#include "cuttlefish/posix/rename.h"
#include "cuttlefish/process/execute.h"
#include "cuttlefish/result/result.h"
Expand Down
11 changes: 11 additions & 0 deletions base/cvd/cuttlefish/posix/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,14 @@ cf_cc_library(
"//cuttlefish/result",
],
)

cf_cc_library(
name = "realpath",
srcs = ["realpath.cc"],
hdrs = ["realpath.h"],
deps = [
"//cuttlefish/posix:strerror",
"//cuttlefish/result:expect",
"//cuttlefish/result:result_type",
],
)
44 changes: 44 additions & 0 deletions base/cvd/cuttlefish/posix/realpath.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "cuttlefish/posix/realpath.h"

#include <errno.h>
#include <limits.h>
#include <linux/limits.h>
#include <stdlib.h>

#include <array>
#include <string>

#include "cuttlefish/posix/strerror.h"
#include "cuttlefish/result/expect.h"
#include "cuttlefish/result/result_type.h"

namespace cuttlefish {

Result<std::string> RealPath(const std::string& path) {
std::array<char, PATH_MAX> buffer{};
char* res;
do {
res = realpath(path.c_str(), buffer.data());
} while (res == nullptr && errno == EINTR);
CF_EXPECTF(res != nullptr, "Could not get real path for path \"{}\": {}",
path, StrError(errno));
return std::string(buffer.data());
}

} // namespace cuttlefish
26 changes: 26 additions & 0 deletions base/cvd/cuttlefish/posix/realpath.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once

#include <string>

#include "cuttlefish/result/result_type.h"

namespace cuttlefish {

Result<std::string> RealPath(const std::string& path);

} // namespace cuttlefish
Loading