diff --git a/base/cvd/cuttlefish/common/libs/utils/BUILD.bazel b/base/cvd/cuttlefish/common/libs/utils/BUILD.bazel index 47f90d4b2b5..1c9c1c197a0 100644 --- a/base/cvd/cuttlefish/common/libs/utils/BUILD.bazel +++ b/base/cvd/cuttlefish/common/libs/utils/BUILD.bazel @@ -423,8 +423,8 @@ cf_cc_library( hdrs = ["wait_for_unix_socket.h"], deps = [ "//cuttlefish/common/libs/fs", - "//cuttlefish/common/libs/utils:files", "//cuttlefish/common/libs/utils:wait_for_file", + "//cuttlefish/files:file_is_socket", "//cuttlefish/process:command", "//cuttlefish/process:managed_stdio", "//cuttlefish/result", diff --git a/base/cvd/cuttlefish/common/libs/utils/files.cpp b/base/cvd/cuttlefish/common/libs/utils/files.cpp index 9c592aceb19..c7c5b0088c8 100644 --- a/base/cvd/cuttlefish/common/libs/utils/files.cpp +++ b/base/cvd/cuttlefish/common/libs/utils/files.cpp @@ -382,11 +382,6 @@ FileSizes SparseFileSizes(const std::string& path) { return (FileSizes){.sparse_size = farthest_seek, .disk_size = data_bytes}; } -bool FileIsSocket(const std::string& path) { - struct stat st{}; - return stat(path.c_str(), &st) == 0 && S_ISSOCK(st.st_mode); -} - Result FindFile(const std::string& path, const std::string& target_name) { std::string ret; diff --git a/base/cvd/cuttlefish/common/libs/utils/files.h b/base/cvd/cuttlefish/common/libs/utils/files.h index e2ed23cff55..5ceb60bfe80 100644 --- a/base/cvd/cuttlefish/common/libs/utils/files.h +++ b/base/cvd/cuttlefish/common/libs/utils/files.h @@ -63,8 +63,6 @@ Result WriteNewFile(const std::string& filepath, std::string_view content, bool MakeFileExecutable(const std::string& path); Result FileModificationTime( const std::string& path); -// Whether a file exists and is a unix socket -bool FileIsSocket(const std::string& path); Result FileOwner(const std::string& path); // The returned value may contain .. or . if these are present in the path diff --git a/base/cvd/cuttlefish/common/libs/utils/wait_for_unix_socket.cpp b/base/cvd/cuttlefish/common/libs/utils/wait_for_unix_socket.cpp index 571cd4b16a8..c04161b7f44 100644 --- a/base/cvd/cuttlefish/common/libs/utils/wait_for_unix_socket.cpp +++ b/base/cvd/cuttlefish/common/libs/utils/wait_for_unix_socket.cpp @@ -26,8 +26,8 @@ #include "absl/log/log.h" #include "cuttlefish/common/libs/fs/shared_fd.h" -#include "cuttlefish/common/libs/utils/files.h" #include "cuttlefish/common/libs/utils/wait_for_file.h" +#include "cuttlefish/files/file_is_socket.h" #include "cuttlefish/process/command.h" #include "cuttlefish/process/managed_stdio.h" #include "cuttlefish/result/result.h" diff --git a/base/cvd/cuttlefish/files/BUILD.bazel b/base/cvd/cuttlefish/files/BUILD.bazel index 168c7a9fa67..525615f2ef5 100644 --- a/base/cvd/cuttlefish/files/BUILD.bazel +++ b/base/cvd/cuttlefish/files/BUILD.bazel @@ -74,6 +74,12 @@ cf_cc_library( hdrs = ["file_exists.h"], ) +cf_cc_library( + name = "file_is_socket", + srcs = ["file_is_socket.cc"], + hdrs = ["file_is_socket.h"], +) + cf_cc_library( name = "is_symlink", srcs = ["is_symlink.cc"], diff --git a/base/cvd/cuttlefish/files/file_is_socket.cc b/base/cvd/cuttlefish/files/file_is_socket.cc new file mode 100644 index 00000000000..fca59e89e5f --- /dev/null +++ b/base/cvd/cuttlefish/files/file_is_socket.cc @@ -0,0 +1,30 @@ +/* + * 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/files/file_is_socket.h" + +#include + +#include + +namespace cuttlefish { + +bool FileIsSocket(const std::string& path) { + struct stat st{}; + return stat(path.c_str(), &st) == 0 && S_ISSOCK(st.st_mode); +} + +} // namespace cuttlefish diff --git a/base/cvd/cuttlefish/files/file_is_socket.h b/base/cvd/cuttlefish/files/file_is_socket.h new file mode 100644 index 00000000000..0377ceee26d --- /dev/null +++ b/base/cvd/cuttlefish/files/file_is_socket.h @@ -0,0 +1,25 @@ +/* + * 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 + +namespace cuttlefish { + +// Whether a file exists and is a unix socket +bool FileIsSocket(const std::string& path); + +} // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/status/BUILD.bazel b/base/cvd/cuttlefish/host/commands/status/BUILD.bazel index a714d46bba5..ea9ad8d83ff 100644 --- a/base/cvd/cuttlefish/host/commands/status/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/status/BUILD.bazel @@ -10,8 +10,8 @@ cf_cc_binary( depend_on_what_you_use_enabled = False, deps = [ "//cuttlefish/common/libs/fs", - "//cuttlefish/common/libs/utils:files", "//cuttlefish/common/libs/utils:tee_logging", + "//cuttlefish/files:file_is_socket", "//cuttlefish/flag_parser", "//cuttlefish/host/libs/command_util", "//cuttlefish/host/libs/config:cuttlefish_config", diff --git a/base/cvd/cuttlefish/host/commands/status/main.cc b/base/cvd/cuttlefish/host/commands/status/main.cc index 4fed21bd16c..a607df6b7d2 100644 --- a/base/cvd/cuttlefish/host/commands/status/main.cc +++ b/base/cvd/cuttlefish/host/commands/status/main.cc @@ -26,8 +26,8 @@ #include "json/value.h" #include "cuttlefish/common/libs/fs/shared_fd.h" -#include "cuttlefish/common/libs/utils/files.h" #include "cuttlefish/common/libs/utils/tee_logging.h" +#include "cuttlefish/files/file_is_socket.h" #include "cuttlefish/flag_parser/flag.h" #include "cuttlefish/flag_parser/gflags_compat.h" #include "cuttlefish/host/libs/command_util/runner/defs.h"