diff --git a/src/storage/CompositeStorage.cxx b/src/storage/CompositeStorage.cxx index fce464db9..660e12f7b 100644 --- a/src/storage/CompositeStorage.cxx +++ b/src/storage/CompositeStorage.cxx @@ -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); diff --git a/src/storage/FileInfo.hxx b/src/storage/FileInfo.hxx index a69b47f0d..5d09bda5c 100644 --- a/src/storage/FileInfo.hxx +++ b/src/storage/FileInfo.hxx @@ -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; } diff --git a/src/storage/plugins/CurlStorage.cxx b/src/storage/plugins/CurlStorage.cxx index 8c29ad5db..072787bc3 100644 --- a/src/storage/plugins/CurlStorage.cxx +++ b/src/storage/plugins/CurlStorage.cxx @@ -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; } };