fs/io/FileReader: add method GetFileInfo()
This commit is contained in:
parent
f04a3ec201
commit
a5760670ef
@ -54,6 +54,7 @@ class FileInfo {
|
|||||||
bool follow_symlinks);
|
bool follow_symlinks);
|
||||||
friend bool GetFileInfo(Path path, FileInfo &info,
|
friend bool GetFileInfo(Path path, FileInfo &info,
|
||||||
Error &error);
|
Error &error);
|
||||||
|
friend class FileReader;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
WIN32_FILE_ATTRIBUTE_DATA data;
|
WIN32_FILE_ATTRIBUTE_DATA data;
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "FileReader.hxx"
|
#include "FileReader.hxx"
|
||||||
#include "fs/FileSystem.hxx"
|
#include "fs/FileInfo.hxx"
|
||||||
#include "util/Error.hxx"
|
#include "util/Error.hxx"
|
||||||
|
|
||||||
#ifdef WIN32
|
#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
|
size_t
|
||||||
FileReader::Read(void *data, size_t size, Error &error)
|
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());
|
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
|
size_t
|
||||||
FileReader::Read(void *data, size_t size, Error &error)
|
FileReader::Read(void *data, size_t size, Error &error)
|
||||||
{
|
{
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
class Path;
|
class Path;
|
||||||
|
class FileInfo;
|
||||||
|
|
||||||
class FileReader final : public Reader {
|
class FileReader final : public Reader {
|
||||||
AllocatedPath path;
|
AllocatedPath path;
|
||||||
@ -79,6 +80,8 @@ public:
|
|||||||
|
|
||||||
void Close();
|
void Close();
|
||||||
|
|
||||||
|
bool GetFileInfo(FileInfo &info, Error &error) const;
|
||||||
|
|
||||||
bool Seek(off_t offset, Error &error);
|
bool Seek(off_t offset, Error &error);
|
||||||
|
|
||||||
/* virtual methods from class Reader */
|
/* virtual methods from class Reader */
|
||||||
|
Loading…
Reference in New Issue
Block a user