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
2 changes: 1 addition & 1 deletion base/cvd/cuttlefish/common/libs/utils/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,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",
Expand Down
5 changes: 0 additions & 5 deletions base/cvd/cuttlefish/common/libs/utils/files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,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<std::string> FindFile(const std::string& path,
const std::string& target_name) {
std::string ret;
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 @@ -63,8 +63,6 @@ Result<void> WriteNewFile(const std::string& filepath, std::string_view content,
bool MakeFileExecutable(const std::string& path);
Result<std::chrono::system_clock::time_point> FileModificationTime(
const std::string& path);
// Whether a file exists and is a unix socket
bool FileIsSocket(const std::string& path);
Result<uid_t> FileOwner(const std::string& path);

// The returned value may contain .. or . if these are present in the path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions base/cvd/cuttlefish/files/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,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"],
Expand Down
30 changes: 30 additions & 0 deletions base/cvd/cuttlefish/files/file_is_socket.cc
Original file line number Diff line number Diff line change
@@ -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 <sys/stat.h>

#include <string>

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
25 changes: 25 additions & 0 deletions base/cvd/cuttlefish/files/file_is_socket.h
Original file line number Diff line number Diff line change
@@ -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 <string>

namespace cuttlefish {

// Whether a file exists and is a unix socket
bool FileIsSocket(const std::string& path);

} // namespace cuttlefish
2 changes: 1 addition & 1 deletion base/cvd/cuttlefish/host/commands/status/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion base/cvd/cuttlefish/host/commands/status/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading