storage/FileInfo: add initializing constructor

This commit is contained in:
Max Kellermann 2017-02-11 22:57:38 +01:00
parent 5cdbad7937
commit 0ccaf4a1ff
3 changed files with 16 additions and 24 deletions

View File

@ -86,12 +86,7 @@ CompositeDirectoryReader::GetInfo(bool follow)
assert(current != names.end());
StorageFileInfo info;
info.type = StorageFileInfo::Type::DIRECTORY;
info.mtime = 0;
info.device = 0;
info.inode = 0;
return info;
return StorageFileInfo(StorageFileInfo::Type::DIRECTORY);
}
static std::string
@ -280,14 +275,8 @@ CompositeStorage::GetInfo(const char *uri, bool follow)
}
const Directory *directory = f.directory->Find(f.uri);
if (directory != nullptr) {
StorageFileInfo info;
info.type = StorageFileInfo::Type::DIRECTORY;
info.mtime = 0;
info.device = 0;
info.inode = 0;
return info;
}
if (directory != nullptr)
return StorageFileInfo(StorageFileInfo::Type::DIRECTORY);
if (error)
std::rethrow_exception(error);

View File

@ -50,6 +50,14 @@ struct StorageFileInfo {
*/
unsigned device, inode;
StorageFileInfo() = default;
explicit constexpr StorageFileInfo(Type _type)
:type(_type),
size(0),
mtime(0),
device(0), inode(0) {}
constexpr bool IsRegular() const {
return type == Type::REGULAR;
}

View File

@ -399,11 +399,8 @@ class HttpGetInfoOperation final : public PropfindOperation {
public:
HttpGetInfoOperation(CurlGlobal &curl, const char *uri)
:PropfindOperation(curl, uri, 0) {
info.type = StorageFileInfo::Type::OTHER;
info.size = 0;
info.mtime = 0;
info.device = info.inode = 0;
:PropfindOperation(curl, uri, 0),
info(StorageFileInfo::Type::OTHER) {
}
const StorageFileInfo &Perform() {
@ -424,7 +421,6 @@ protected:
info.mtime = !IsNegative(r.mtime)
? std::chrono::system_clock::to_time_t(r.mtime)
: 0;
info.device = info.inode = 0;
}
};
@ -514,14 +510,13 @@ protected:
entries.emplace_front(std::string(name.data, name.size));
auto &info = entries.front().info;
info.type = r.collection
? StorageFileInfo::Type::DIRECTORY
: StorageFileInfo::Type::REGULAR;
info = StorageFileInfo(r.collection
? StorageFileInfo::Type::DIRECTORY
: StorageFileInfo::Type::REGULAR);
info.size = r.length;
info.mtime = !IsNegative(r.mtime)
? std::chrono::system_clock::to_time_t(r.mtime)
: 0;
info.device = info.inode = 0;
}
};