diff options
Diffstat (limited to '')
-rw-r--r-- | src/fs/FileInfo.hxx | 1 | ||||
-rw-r--r-- | src/fs/io/FileReader.cxx | 23 | ||||
-rw-r--r-- | src/fs/io/FileReader.hxx | 3 |
3 files changed, 26 insertions, 1 deletions
diff --git a/src/fs/FileInfo.hxx b/src/fs/FileInfo.hxx index 3805d3ef0..ad0fb4064 100644 --- a/src/fs/FileInfo.hxx +++ b/src/fs/FileInfo.hxx @@ -54,6 +54,7 @@ class FileInfo { bool follow_symlinks); friend bool GetFileInfo(Path path, FileInfo &info, Error &error); + friend class FileReader; #ifdef WIN32 WIN32_FILE_ATTRIBUTE_DATA data; diff --git a/src/fs/io/FileReader.cxx b/src/fs/io/FileReader.cxx index 474431ef8..e54f6f3a8 100644 --- a/src/fs/io/FileReader.cxx +++ b/src/fs/io/FileReader.cxx @@ -19,7 +19,7 @@ #include "config.h" #include "FileReader.hxx" -#include "fs/FileSystem.hxx" +#include "fs/FileInfo.hxx" #include "util/Error.hxx" #ifdef WIN32 @@ -36,6 +36,14 @@ FileReader::FileReader(Path _path, Error &error) } } +bool +FileReader::GetFileInfo(FileInfo &info, Error &error) const +{ + assert(IsDefined()); + + return ::GetFileInfo(path, info, error); +} + size_t FileReader::Read(void *data, size_t size, Error &error) { @@ -83,6 +91,19 @@ FileReader::FileReader(Path _path, Error &error) error.FormatErrno("Failed to open %s", path.c_str()); } +bool +FileReader::GetFileInfo(FileInfo &info, Error &error) const +{ + assert(IsDefined()); + + const bool success = fstat(fd.Get(), &info.st) == 0; + if (!success) + error.FormatErrno("Failed to access %s", + path.ToUTF8().c_str()); + + return success; +} + size_t FileReader::Read(void *data, size_t size, Error &error) { diff --git a/src/fs/io/FileReader.hxx b/src/fs/io/FileReader.hxx index 53651380f..c67bd6d77 100644 --- a/src/fs/io/FileReader.hxx +++ b/src/fs/io/FileReader.hxx @@ -36,6 +36,7 @@ #endif class Path; +class FileInfo; class FileReader final : public Reader { AllocatedPath path; @@ -79,6 +80,8 @@ public: void Close(); + bool GetFileInfo(FileInfo &info, Error &error) const; + bool Seek(off_t offset, Error &error); /* virtual methods from class Reader */ |