diff --git a/src/io/FileReader.cxx b/src/io/FileReader.cxx index 93a0b5fc6..0d72e57ba 100644 --- a/src/io/FileReader.cxx +++ b/src/io/FileReader.cxx @@ -3,6 +3,7 @@ #include "FileReader.hxx" #include "lib/fmt/PathFormatter.hxx" +#include "fs/AllocatedPath.hxx" #include "fs/FileInfo.hxx" #include "lib/fmt/SystemError.hxx" #include "io/Open.hxx" @@ -11,9 +12,8 @@ #ifdef _WIN32 -FileReader::FileReader(Path _path) - :path(_path), - handle(CreateFile(path.c_str(), GENERIC_READ, FILE_SHARE_READ, +FileReader::FileReader(Path path) + :handle(CreateFile(path.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr)) { @@ -36,7 +36,7 @@ FileReader::Read(std::span dest) DWORD nbytes; if (!ReadFile(handle, dest.data(), dest.size(), &nbytes, nullptr)) - throw FmtLastError("Failed to read from {}", path); + throw MakeLastError("Failed to read from file"); return nbytes; } @@ -63,8 +63,8 @@ FileReader::Skip(off_t offset) #else -FileReader::FileReader(Path _path) - :path(_path), fd(OpenReadOnly(path.c_str())) +FileReader::FileReader(Path path) + :fd(OpenReadOnly(path.c_str())) { } @@ -76,7 +76,7 @@ FileReader::GetFileInfo() const FileInfo info; const bool success = fstat(fd.Get(), &info.st) == 0; if (!success) - throw FmtErrno("Failed to access {}", path); + throw MakeErrno("Failed to access file"); return info; } @@ -88,7 +88,7 @@ FileReader::Read(std::span dest) ssize_t nbytes = fd.Read(dest); if (nbytes < 0) - throw FmtErrno("Failed to read from {}", path); + throw MakeErrno("Failed to read from file"); return nbytes; } diff --git a/src/io/FileReader.hxx b/src/io/FileReader.hxx index 431f9afa2..6a5cf36ee 100644 --- a/src/io/FileReader.hxx +++ b/src/io/FileReader.hxx @@ -4,7 +4,6 @@ #pragma once #include "Reader.hxx" -#include "fs/AllocatedPath.hxx" #ifdef _WIN32 #include @@ -16,13 +15,14 @@ #endif #include +#include // for std::exchange() + +#include // for off_t class Path; class FileInfo; class FileReader final : public Reader { - AllocatedPath path; - #ifdef _WIN32 HANDLE handle; #else @@ -34,8 +34,7 @@ public: #ifdef _WIN32 FileReader(FileReader &&other) noexcept - :path(std::move(other.path)), - handle(std::exchange(other.handle, INVALID_HANDLE_VALUE)) {} + :handle(std::exchange(other.handle, INVALID_HANDLE_VALUE)) {} ~FileReader() noexcept { if (handle != INVALID_HANDLE_VALUE) @@ -43,8 +42,7 @@ public: } #else FileReader(FileReader &&other) noexcept - :path(std::move(other.path)), - fd(std::move(other.fd)) {} + :fd(std::move(other.fd)) {} #endif