Skip to content
Merged
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
26 changes: 7 additions & 19 deletions src/libutil/file-system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -252,21 +252,15 @@ Path readLink(const Path & path)

std::string readFile(const Path & path)
{
AutoCloseFD fd = toDescriptor(open(
path.c_str(),
O_RDONLY
#ifdef O_CLOEXEC
| O_CLOEXEC
#endif
));
if (!fd)
throw SysError("opening file '%1%'", path);
return readFile(fd.get());
return readFile(std::filesystem::path(path));
}

std::string readFile(const std::filesystem::path & path)
{
return readFile(os_string_to_string(PathViewNG{path}));
AutoCloseFD fd = openFileReadonly(path);
if (!fd)
throw NativeSysError("opening file %1%", path);
return readFile(fd.get());
}

void readFile(const Path & path, Sink & sink, bool memory_map)
Expand All @@ -285,15 +279,9 @@ void readFile(const Path & path, Sink & sink, bool memory_map)
}

// Stream the file instead if memory-mapping fails or is disabled.
AutoCloseFD fd = toDescriptor(open(
path.c_str(),
O_RDONLY
#ifdef O_CLOEXEC
| O_CLOEXEC
#endif
));
AutoCloseFD fd = openFileReadonly(std::filesystem::path(path));
if (!fd)
throw SysError("opening file '%s'", path);
throw NativeSysError("opening file %s", path);
drainFD(fd.get(), sink);
}

Expand Down
2 changes: 1 addition & 1 deletion src/libutil/nar-accessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ GetNarBytes seekableGetNarBytes(const std::filesystem::path & path)
{
AutoCloseFD fd = openFileReadonly(path);
if (!fd)
throw NativeSysError("opening NAR cache file '%s'", path);
throw NativeSysError("opening NAR cache file %s", path);

return [inner = seekableGetNarBytes(fd.get()), fd = make_ref<AutoCloseFD>(std::move(fd))](
uint64_t offset, uint64_t length) { return inner(offset, length); };
Expand Down
6 changes: 3 additions & 3 deletions src/nix/cat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct CmdCatStore : StoreCommand, MixCat

struct CmdCatNar : StoreCommand, MixCat
{
Path narPath;
std::filesystem::path narPath;

std::string path;

Expand All @@ -76,9 +76,9 @@ struct CmdCatNar : StoreCommand, MixCat

void run(ref<Store> store) override
{
AutoCloseFD fd = toDescriptor(open(narPath.c_str(), O_RDONLY));
AutoCloseFD fd = openFileReadonly(narPath);
if (!fd)
throw SysError("opening NAR file '%s'", narPath);
throw NativeSysError("opening NAR file %s", narPath);
auto source = FdSource{fd.get()};

struct CatRegularFileSink : NullFileSystemObjectSink
Expand Down
6 changes: 3 additions & 3 deletions src/nix/ls.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ struct CmdLsStore : StoreCommand, MixLs

struct CmdLsNar : Command, MixLs
{
Path narPath;
std::filesystem::path narPath;

std::string path;

Expand All @@ -150,9 +150,9 @@ struct CmdLsNar : Command, MixLs

void run() override
{
AutoCloseFD fd = toDescriptor(open(narPath.c_str(), O_RDONLY));
AutoCloseFD fd = openFileReadonly(narPath);
if (!fd)
throw SysError("opening NAR file '%s'", narPath);
throw NativeSysError("opening NAR file %s", narPath);
auto source = FdSource{fd.get()};
list(makeLazyNarAccessor(source, seekableGetNarBytes(fd.get())), CanonPath{path});
}
Expand Down
Loading