Skip to content

Commit cf81a93

Browse files
committed
Replace libbase's WriteStringToFd with WriteExact
Bug: 502705785
1 parent de2f08a commit cf81a93

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

base/cvd/cuttlefish/host/commands/assemble_cvd/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,6 @@ cf_cc_library(
614614
"//cuttlefish/host/libs/config:config_utils",
615615
"//cuttlefish/host/libs/config:known_paths",
616616
"//cuttlefish/io:shared_fd",
617-
"//cuttlefish/posix:strerror",
618617
"//cuttlefish/result",
619618
"//libbase",
620619
"@abseil-cpp//absl/log",

base/cvd/cuttlefish/host/commands/assemble_cvd/vendor_dlkm_utils.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
#include "cuttlefish/host/libs/config/config_utils.h"
4646
#include "cuttlefish/host/libs/config/known_paths.h"
4747
#include "cuttlefish/io/shared_fd.h"
48-
#include "cuttlefish/posix/strerror.h"
4948

5049
namespace cuttlefish {
5150

@@ -84,12 +83,13 @@ bool WriteLinesToFile(const Container& lines, const std::string& path) {
8483
Result<void> WriteFsConfig(const std::string& output_path,
8584
const std::string& fs_root,
8685
const std::string& mount_point) {
87-
android::base::unique_fd fd(open(
88-
output_path.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644));
89-
CF_EXPECTF(fd.ok(), "Couldn't open '{}': '{}'", output_path, StrError(errno));
86+
SharedFD fd = SharedFD::Open(output_path,
87+
O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
88+
CF_EXPECTF(fd->IsOpen(), "Couldn't open '{}': '{}'", output_path,
89+
fd->StrError());
9090
static constexpr std::string_view kBeginning =
9191
" 0 0 755 selabel=u:object_r:rootfs:s0 capabilities=0x0\n";
92-
CF_EXPECTF(android::base::WriteStringToFd(kBeginning, fd),
92+
CF_EXPECTF(WriteAll(fd, kBeginning) == kBeginning.size(),
9393
"Failed to write to '{}'", output_path);
9494
Result<void> res = WalkDirectory(
9595
fs_root,
@@ -100,10 +100,10 @@ Result<void> WriteFsConfig(const std::string& output_path,
100100
const std::string fs_context = DirectoryExists(file_path)
101101
? " 0 0 755 capabilities=0x0\n"
102102
: " 0 0 644 capabilities=0x0\n";
103-
CF_EXPECTF(android::base::WriteStringToFd(
104-
mount_point + "/" + filename + fs_context, fd),
103+
std::string to_write = mount_point + "/" + filename + fs_context;
104+
CF_EXPECTF(WriteAll(fd, to_write) == to_write.size(),
105105
"Failed to write to '{}': '{}'", output_path,
106-
StrError(errno));
106+
fd->StrError());
107107
return {};
108108
});
109109
CF_EXPECT(std::move(res));

0 commit comments

Comments
 (0)