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
5049namespace cuttlefish {
5150
@@ -84,12 +83,13 @@ bool WriteLinesToFile(const Container& lines, const std::string& path) {
8483Result<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