storage/FileInfo: rename to StorageFileInfo
This commit is contained in:
parent
e1a434edbc
commit
2d06a8e880
@ -83,7 +83,7 @@ Song::UpdateFile(Storage &storage)
|
|||||||
{
|
{
|
||||||
const auto &relative_uri = GetURI();
|
const auto &relative_uri = GetURI();
|
||||||
|
|
||||||
FileInfo info;
|
StorageFileInfo info;
|
||||||
if (!storage.GetInfo(relative_uri.c_str(), true, info, IgnoreError()))
|
if (!storage.GetInfo(relative_uri.c_str(), true, info, IgnoreError()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -64,23 +64,23 @@ handle_listfiles_storage(Client &client, StorageDirectoryReader &reader,
|
|||||||
if (skip_path(name_utf8))
|
if (skip_path(name_utf8))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
FileInfo info;
|
StorageFileInfo info;
|
||||||
if (!reader.GetInfo(false, info, error))
|
if (!reader.GetInfo(false, info, error))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
switch (info.type) {
|
switch (info.type) {
|
||||||
case FileInfo::Type::OTHER:
|
case StorageFileInfo::Type::OTHER:
|
||||||
/* ignore */
|
/* ignore */
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case FileInfo::Type::REGULAR:
|
case StorageFileInfo::Type::REGULAR:
|
||||||
client_printf(client, "file: %s\n"
|
client_printf(client, "file: %s\n"
|
||||||
"size: %" PRIu64 "\n",
|
"size: %" PRIu64 "\n",
|
||||||
name_utf8,
|
name_utf8,
|
||||||
info.size);
|
info.size);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FileInfo::Type::DIRECTORY:
|
case StorageFileInfo::Type::DIRECTORY:
|
||||||
client_printf(client, "directory: %s\n", name_utf8);
|
client_printf(client, "directory: %s\n", name_utf8);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ class UpdateArchiveVisitor final : public ArchiveVisitor {
|
|||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
UpdateWalk::UpdateArchiveFile(Directory &parent, const char *name,
|
UpdateWalk::UpdateArchiveFile(Directory &parent, const char *name,
|
||||||
const FileInfo &info,
|
const StorageFileInfo &info,
|
||||||
const ArchivePlugin &plugin)
|
const ArchivePlugin &plugin)
|
||||||
{
|
{
|
||||||
db_lock();
|
db_lock();
|
||||||
@ -156,7 +156,7 @@ UpdateWalk::UpdateArchiveFile(Directory &parent, const char *name,
|
|||||||
bool
|
bool
|
||||||
UpdateWalk::UpdateArchiveFile(Directory &directory,
|
UpdateWalk::UpdateArchiveFile(Directory &directory,
|
||||||
const char *name, const char *suffix,
|
const char *name, const char *suffix,
|
||||||
const FileInfo &info)
|
const StorageFileInfo &info)
|
||||||
{
|
{
|
||||||
const ArchivePlugin *plugin = archive_plugin_from_suffix(suffix);
|
const ArchivePlugin *plugin = archive_plugin_from_suffix(suffix);
|
||||||
if (plugin == nullptr)
|
if (plugin == nullptr)
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
|
|
||||||
Directory *
|
Directory *
|
||||||
UpdateWalk::MakeDirectoryIfModified(Directory &parent, const char *name,
|
UpdateWalk::MakeDirectoryIfModified(Directory &parent, const char *name,
|
||||||
const FileInfo &info)
|
const StorageFileInfo &info)
|
||||||
{
|
{
|
||||||
Directory *directory = parent.FindChild(name);
|
Directory *directory = parent.FindChild(name);
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ SupportsContainerSuffix(const DecoderPlugin &plugin, const char *suffix)
|
|||||||
bool
|
bool
|
||||||
UpdateWalk::UpdateContainerFile(Directory &directory,
|
UpdateWalk::UpdateContainerFile(Directory &directory,
|
||||||
const char *name, const char *suffix,
|
const char *name, const char *suffix,
|
||||||
const FileInfo &info)
|
const StorageFileInfo &info)
|
||||||
{
|
{
|
||||||
const DecoderPlugin *_plugin = decoder_plugins_find([suffix](const DecoderPlugin &plugin){
|
const DecoderPlugin *_plugin = decoder_plugins_find([suffix](const DecoderPlugin &plugin){
|
||||||
return SupportsContainerSuffix(plugin, suffix);
|
return SupportsContainerSuffix(plugin, suffix);
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
bool
|
bool
|
||||||
GetInfo(Storage &storage, const char *uri_utf8, FileInfo &info)
|
GetInfo(Storage &storage, const char *uri_utf8, StorageFileInfo &info)
|
||||||
{
|
{
|
||||||
Error error;
|
Error error;
|
||||||
bool success = storage.GetInfo(uri_utf8, true, info, error);
|
bool success = storage.GetInfo(uri_utf8, true, info, error);
|
||||||
@ -43,7 +43,7 @@ GetInfo(Storage &storage, const char *uri_utf8, FileInfo &info)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
GetInfo(StorageDirectoryReader &reader, FileInfo &info)
|
GetInfo(StorageDirectoryReader &reader, StorageFileInfo &info)
|
||||||
{
|
{
|
||||||
Error error;
|
Error error;
|
||||||
bool success = reader.GetInfo(true, info, error);
|
bool success = reader.GetInfo(true, info, error);
|
||||||
@ -55,7 +55,7 @@ GetInfo(StorageDirectoryReader &reader, FileInfo &info)
|
|||||||
bool
|
bool
|
||||||
DirectoryExists(Storage &storage, const Directory &directory)
|
DirectoryExists(Storage &storage, const Directory &directory)
|
||||||
{
|
{
|
||||||
FileInfo info;
|
StorageFileInfo info;
|
||||||
if (!storage.GetInfo(directory.GetPath(), true, info, IgnoreError()))
|
if (!storage.GetInfo(directory.GetPath(), true, info, IgnoreError()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ DirectoryExists(Storage &storage, const Directory &directory)
|
|||||||
|
|
||||||
static bool
|
static bool
|
||||||
GetDirectoryChildInfo(Storage &storage, const Directory &directory,
|
GetDirectoryChildInfo(Storage &storage, const Directory &directory,
|
||||||
const char *name_utf8, FileInfo &info, Error &error)
|
const char *name_utf8, StorageFileInfo &info, Error &error)
|
||||||
{
|
{
|
||||||
const auto uri_utf8 = PathTraitsUTF8::Build(directory.GetPath(),
|
const auto uri_utf8 = PathTraitsUTF8::Build(directory.GetPath(),
|
||||||
name_utf8);
|
name_utf8);
|
||||||
@ -78,7 +78,7 @@ bool
|
|||||||
directory_child_is_regular(Storage &storage, const Directory &directory,
|
directory_child_is_regular(Storage &storage, const Directory &directory,
|
||||||
const char *name_utf8)
|
const char *name_utf8)
|
||||||
{
|
{
|
||||||
FileInfo info;
|
StorageFileInfo info;
|
||||||
return GetDirectoryChildInfo(storage, directory, name_utf8, info,
|
return GetDirectoryChildInfo(storage, directory, name_utf8, info,
|
||||||
IgnoreError()) &&
|
IgnoreError()) &&
|
||||||
info.IsRegular();
|
info.IsRegular();
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
#include "Compiler.h"
|
#include "Compiler.h"
|
||||||
|
|
||||||
struct Directory;
|
struct Directory;
|
||||||
struct FileInfo;
|
struct StorageFileInfo;
|
||||||
class Storage;
|
class Storage;
|
||||||
class StorageDirectoryReader;
|
class StorageDirectoryReader;
|
||||||
|
|
||||||
@ -33,14 +33,14 @@ class StorageDirectoryReader;
|
|||||||
* returning them.
|
* returning them.
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
GetInfo(Storage &storage, const char *uri_utf8, FileInfo &info);
|
GetInfo(Storage &storage, const char *uri_utf8, StorageFileInfo &info);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper for LocalDirectoryReader::GetInfo() that logs errors
|
* Wrapper for LocalDirectoryReader::GetInfo() that logs errors
|
||||||
* instead of returning them.
|
* instead of returning them.
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
GetInfo(StorageDirectoryReader &reader, FileInfo &info);
|
GetInfo(StorageDirectoryReader &reader, StorageFileInfo &info);
|
||||||
|
|
||||||
gcc_pure
|
gcc_pure
|
||||||
bool
|
bool
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
inline void
|
inline void
|
||||||
UpdateWalk::UpdateSongFile2(Directory &directory,
|
UpdateWalk::UpdateSongFile2(Directory &directory,
|
||||||
const char *name, const char *suffix,
|
const char *name, const char *suffix,
|
||||||
const FileInfo &info)
|
const StorageFileInfo &info)
|
||||||
{
|
{
|
||||||
db_lock();
|
db_lock();
|
||||||
Song *song = directory.FindSong(name);
|
Song *song = directory.FindSong(name);
|
||||||
@ -93,7 +93,7 @@ UpdateWalk::UpdateSongFile2(Directory &directory,
|
|||||||
bool
|
bool
|
||||||
UpdateWalk::UpdateSongFile(Directory &directory,
|
UpdateWalk::UpdateSongFile(Directory &directory,
|
||||||
const char *name, const char *suffix,
|
const char *name, const char *suffix,
|
||||||
const FileInfo &info)
|
const StorageFileInfo &info)
|
||||||
{
|
{
|
||||||
if (!decoder_plugins_supports_suffix(suffix))
|
if (!decoder_plugins_supports_suffix(suffix))
|
||||||
return false;
|
return false;
|
||||||
|
@ -67,7 +67,7 @@ UpdateWalk::UpdateWalk(EventLoop &_loop, DatabaseListener &_listener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
directory_set_stat(Directory &dir, const FileInfo &info)
|
directory_set_stat(Directory &dir, const StorageFileInfo &info)
|
||||||
{
|
{
|
||||||
dir.inode = info.inode;
|
dir.inode = info.inode;
|
||||||
dir.device = info.device;
|
dir.device = info.device;
|
||||||
@ -140,7 +140,7 @@ UpdateWalk::PurgeDeletedFromDirectory(Directory &directory)
|
|||||||
static bool
|
static bool
|
||||||
update_directory_stat(Storage &storage, Directory &directory)
|
update_directory_stat(Storage &storage, Directory &directory)
|
||||||
{
|
{
|
||||||
FileInfo info;
|
StorageFileInfo info;
|
||||||
if (!GetInfo(storage, directory.GetPath(), info))
|
if (!GetInfo(storage, directory.GetPath(), info))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -190,7 +190,7 @@ FindAncestorLoop(Storage &storage, Directory *parent,
|
|||||||
inline bool
|
inline bool
|
||||||
UpdateWalk::UpdatePlaylistFile(Directory &directory,
|
UpdateWalk::UpdatePlaylistFile(Directory &directory,
|
||||||
const char *name, const char *suffix,
|
const char *name, const char *suffix,
|
||||||
const FileInfo &info)
|
const StorageFileInfo &info)
|
||||||
{
|
{
|
||||||
if (!playlist_suffix_supported(suffix))
|
if (!playlist_suffix_supported(suffix))
|
||||||
return false;
|
return false;
|
||||||
@ -206,7 +206,7 @@ UpdateWalk::UpdatePlaylistFile(Directory &directory,
|
|||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
UpdateWalk::UpdateRegularFile(Directory &directory,
|
UpdateWalk::UpdateRegularFile(Directory &directory,
|
||||||
const char *name, const FileInfo &info)
|
const char *name, const StorageFileInfo &info)
|
||||||
{
|
{
|
||||||
const char *suffix = uri_get_suffix(name);
|
const char *suffix = uri_get_suffix(name);
|
||||||
if (suffix == nullptr)
|
if (suffix == nullptr)
|
||||||
@ -219,7 +219,7 @@ UpdateWalk::UpdateRegularFile(Directory &directory,
|
|||||||
|
|
||||||
void
|
void
|
||||||
UpdateWalk::UpdateDirectoryChild(Directory &directory,
|
UpdateWalk::UpdateDirectoryChild(Directory &directory,
|
||||||
const char *name, const FileInfo &info)
|
const char *name, const StorageFileInfo &info)
|
||||||
{
|
{
|
||||||
assert(strchr(name, '/') == nullptr);
|
assert(strchr(name, '/') == nullptr);
|
||||||
|
|
||||||
@ -327,7 +327,7 @@ UpdateWalk::SkipSymlink(const Directory *directory,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
UpdateWalk::UpdateDirectory(Directory &directory, const FileInfo &info)
|
UpdateWalk::UpdateDirectory(Directory &directory, const StorageFileInfo &info)
|
||||||
{
|
{
|
||||||
assert(info.IsDirectory());
|
assert(info.IsDirectory());
|
||||||
|
|
||||||
@ -370,7 +370,7 @@ UpdateWalk::UpdateDirectory(Directory &directory, const FileInfo &info)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileInfo info2;
|
StorageFileInfo info2;
|
||||||
if (!GetInfo(*reader, info2)) {
|
if (!GetInfo(*reader, info2)) {
|
||||||
modified |= editor.DeleteNameIn(directory, name_utf8);
|
modified |= editor.DeleteNameIn(directory, name_utf8);
|
||||||
continue;
|
continue;
|
||||||
@ -400,7 +400,7 @@ UpdateWalk::DirectoryMakeChildChecked(Directory &parent,
|
|||||||
return directory;
|
return directory;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileInfo info;
|
StorageFileInfo info;
|
||||||
if (!GetInfo(storage, uri_utf8, info) ||
|
if (!GetInfo(storage, uri_utf8, info) ||
|
||||||
FindAncestorLoop(storage, &parent, info.inode, info.device))
|
FindAncestorLoop(storage, &parent, info.inode, info.device))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -462,7 +462,7 @@ UpdateWalk::UpdateUri(Directory &root, const char *uri)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileInfo info;
|
StorageFileInfo info;
|
||||||
if (!GetInfo(storage, uri, info)) {
|
if (!GetInfo(storage, uri, info)) {
|
||||||
modified |= editor.DeleteNameIn(*parent, name);
|
modified |= editor.DeleteNameIn(*parent, name);
|
||||||
return;
|
return;
|
||||||
@ -480,7 +480,7 @@ UpdateWalk::Walk(Directory &root, const char *path, bool discard)
|
|||||||
if (path != nullptr && !isRootDirectory(path)) {
|
if (path != nullptr && !isRootDirectory(path)) {
|
||||||
UpdateUri(root, path);
|
UpdateUri(root, path);
|
||||||
} else {
|
} else {
|
||||||
FileInfo info;
|
StorageFileInfo info;
|
||||||
if (!GetInfo(storage, "", info))
|
if (!GetInfo(storage, "", info))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
struct stat;
|
struct stat;
|
||||||
struct FileInfo;
|
struct StorageFileInfo;
|
||||||
struct Directory;
|
struct Directory;
|
||||||
struct ArchivePlugin;
|
struct ArchivePlugin;
|
||||||
class Storage;
|
class Storage;
|
||||||
@ -89,15 +89,15 @@ private:
|
|||||||
|
|
||||||
void UpdateSongFile2(Directory &directory,
|
void UpdateSongFile2(Directory &directory,
|
||||||
const char *name, const char *suffix,
|
const char *name, const char *suffix,
|
||||||
const FileInfo &info);
|
const StorageFileInfo &info);
|
||||||
|
|
||||||
bool UpdateSongFile(Directory &directory,
|
bool UpdateSongFile(Directory &directory,
|
||||||
const char *name, const char *suffix,
|
const char *name, const char *suffix,
|
||||||
const FileInfo &info);
|
const StorageFileInfo &info);
|
||||||
|
|
||||||
bool UpdateContainerFile(Directory &directory,
|
bool UpdateContainerFile(Directory &directory,
|
||||||
const char *name, const char *suffix,
|
const char *name, const char *suffix,
|
||||||
const FileInfo &info);
|
const StorageFileInfo &info);
|
||||||
|
|
||||||
|
|
||||||
#ifdef ENABLE_ARCHIVE
|
#ifdef ENABLE_ARCHIVE
|
||||||
@ -105,10 +105,10 @@ private:
|
|||||||
|
|
||||||
bool UpdateArchiveFile(Directory &directory,
|
bool UpdateArchiveFile(Directory &directory,
|
||||||
const char *name, const char *suffix,
|
const char *name, const char *suffix,
|
||||||
const FileInfo &info);
|
const StorageFileInfo &info);
|
||||||
|
|
||||||
void UpdateArchiveFile(Directory &directory, const char *name,
|
void UpdateArchiveFile(Directory &directory, const char *name,
|
||||||
const FileInfo &info,
|
const StorageFileInfo &info,
|
||||||
const ArchivePlugin &plugin);
|
const ArchivePlugin &plugin);
|
||||||
|
|
||||||
|
|
||||||
@ -116,22 +116,24 @@ private:
|
|||||||
bool UpdateArchiveFile(gcc_unused Directory &directory,
|
bool UpdateArchiveFile(gcc_unused Directory &directory,
|
||||||
gcc_unused const char *name,
|
gcc_unused const char *name,
|
||||||
gcc_unused const char *suffix,
|
gcc_unused const char *suffix,
|
||||||
gcc_unused const FileInfo &info) {
|
gcc_unused const StorageFileInfo &info) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool UpdatePlaylistFile(Directory &directory,
|
bool UpdatePlaylistFile(Directory &directory,
|
||||||
const char *name, const char *suffix,
|
const char *name, const char *suffix,
|
||||||
const FileInfo &info);
|
const StorageFileInfo &info);
|
||||||
|
|
||||||
bool UpdateRegularFile(Directory &directory,
|
bool UpdateRegularFile(Directory &directory,
|
||||||
const char *name, const FileInfo &info);
|
const char *name, const StorageFileInfo &info);
|
||||||
|
|
||||||
void UpdateDirectoryChild(Directory &directory,
|
void UpdateDirectoryChild(Directory &directory,
|
||||||
const char *name, const FileInfo &info);
|
const char *name,
|
||||||
|
const StorageFileInfo &info);
|
||||||
|
|
||||||
bool UpdateDirectory(Directory &directory, const FileInfo &info);
|
bool UpdateDirectory(Directory &directory,
|
||||||
|
const StorageFileInfo &info);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the specified directory object if it does not exist
|
* Create the specified directory object if it does not exist
|
||||||
@ -142,7 +144,7 @@ private:
|
|||||||
* The caller must lock the database.
|
* The caller must lock the database.
|
||||||
*/
|
*/
|
||||||
Directory *MakeDirectoryIfModified(Directory &parent, const char *name,
|
Directory *MakeDirectoryIfModified(Directory &parent, const char *name,
|
||||||
const FileInfo &info);
|
const StorageFileInfo &info);
|
||||||
|
|
||||||
Directory *DirectoryMakeChildChecked(Directory &parent,
|
Directory *DirectoryMakeChildChecked(Directory &parent,
|
||||||
const char *uri_utf8,
|
const char *uri_utf8,
|
||||||
|
@ -56,7 +56,7 @@ public:
|
|||||||
|
|
||||||
/* virtual methods from class StorageDirectoryReader */
|
/* virtual methods from class StorageDirectoryReader */
|
||||||
const char *Read() override;
|
const char *Read() override;
|
||||||
bool GetInfo(bool follow, FileInfo &info, Error &error) override;
|
bool GetInfo(bool follow, StorageFileInfo &info, Error &error) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
@ -81,7 +81,7 @@ CompositeDirectoryReader::Read()
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
CompositeDirectoryReader::GetInfo(bool follow, FileInfo &info,
|
CompositeDirectoryReader::GetInfo(bool follow, StorageFileInfo &info,
|
||||||
Error &error)
|
Error &error)
|
||||||
{
|
{
|
||||||
if (other != nullptr)
|
if (other != nullptr)
|
||||||
@ -89,7 +89,7 @@ CompositeDirectoryReader::GetInfo(bool follow, FileInfo &info,
|
|||||||
|
|
||||||
assert(current != names.end());
|
assert(current != names.end());
|
||||||
|
|
||||||
info.type = FileInfo::Type::DIRECTORY;
|
info.type = StorageFileInfo::Type::DIRECTORY;
|
||||||
info.mtime = 0;
|
info.mtime = 0;
|
||||||
info.device = 0;
|
info.device = 0;
|
||||||
info.inode = 0;
|
info.inode = 0;
|
||||||
@ -275,7 +275,7 @@ CompositeStorage::FindStorage(const char *uri, Error &error) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
CompositeStorage::GetInfo(const char *uri, bool follow, FileInfo &info,
|
CompositeStorage::GetInfo(const char *uri, bool follow, StorageFileInfo &info,
|
||||||
Error &error)
|
Error &error)
|
||||||
{
|
{
|
||||||
const ScopeLock protect(mutex);
|
const ScopeLock protect(mutex);
|
||||||
@ -288,7 +288,7 @@ CompositeStorage::GetInfo(const char *uri, bool follow, FileInfo &info,
|
|||||||
const Directory *directory = f.directory->Find(f.uri);
|
const Directory *directory = f.directory->Find(f.uri);
|
||||||
if (directory != nullptr) {
|
if (directory != nullptr) {
|
||||||
error.Clear();
|
error.Clear();
|
||||||
info.type = FileInfo::Type::DIRECTORY;
|
info.type = StorageFileInfo::Type::DIRECTORY;
|
||||||
info.mtime = 0;
|
info.mtime = 0;
|
||||||
info.device = 0;
|
info.device = 0;
|
||||||
info.inode = 0;
|
info.inode = 0;
|
||||||
|
@ -122,7 +122,7 @@ public:
|
|||||||
bool Unmount(const char *uri);
|
bool Unmount(const char *uri);
|
||||||
|
|
||||||
/* virtual methods from class Storage */
|
/* virtual methods from class Storage */
|
||||||
bool GetInfo(const char *uri, bool follow, FileInfo &info,
|
bool GetInfo(const char *uri, bool follow, StorageFileInfo &info,
|
||||||
Error &error) override;
|
Error &error) override;
|
||||||
|
|
||||||
StorageDirectoryReader *OpenDirectory(const char *uri,
|
StorageDirectoryReader *OpenDirectory(const char *uri,
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
struct FileInfo {
|
struct StorageFileInfo {
|
||||||
enum class Type : uint8_t {
|
enum class Type : uint8_t {
|
||||||
OTHER,
|
OTHER,
|
||||||
REGULAR,
|
REGULAR,
|
||||||
|
@ -37,7 +37,8 @@ MemoryStorageDirectoryReader::Read()
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
MemoryStorageDirectoryReader::GetInfo(gcc_unused bool follow, FileInfo &info,
|
MemoryStorageDirectoryReader::GetInfo(gcc_unused bool follow,
|
||||||
|
StorageFileInfo &info,
|
||||||
gcc_unused Error &error)
|
gcc_unused Error &error)
|
||||||
{
|
{
|
||||||
assert(!first);
|
assert(!first);
|
||||||
|
@ -36,7 +36,7 @@ public:
|
|||||||
struct Entry {
|
struct Entry {
|
||||||
std::string name;
|
std::string name;
|
||||||
|
|
||||||
FileInfo info;
|
StorageFileInfo info;
|
||||||
|
|
||||||
template<typename N>
|
template<typename N>
|
||||||
explicit Entry(N &&_name):name(std::forward<N>(_name)) {}
|
explicit Entry(N &&_name):name(std::forward<N>(_name)) {}
|
||||||
@ -61,7 +61,8 @@ public:
|
|||||||
|
|
||||||
/* virtual methods from class StorageDirectoryReader */
|
/* virtual methods from class StorageDirectoryReader */
|
||||||
const char *Read() override;
|
const char *Read() override;
|
||||||
bool GetInfo(bool follow, FileInfo &info, Error &error) override;
|
bool GetInfo(bool follow, StorageFileInfo &info,
|
||||||
|
Error &error) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
struct FileInfo;
|
struct StorageFileInfo;
|
||||||
class AllocatedPath;
|
class AllocatedPath;
|
||||||
class Error;
|
class Error;
|
||||||
|
|
||||||
@ -36,7 +36,8 @@ public:
|
|||||||
virtual ~StorageDirectoryReader() {}
|
virtual ~StorageDirectoryReader() {}
|
||||||
|
|
||||||
virtual const char *Read() = 0;
|
virtual const char *Read() = 0;
|
||||||
virtual bool GetInfo(bool follow, FileInfo &info, Error &error) = 0;
|
virtual bool GetInfo(bool follow, StorageFileInfo &info,
|
||||||
|
Error &error) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Storage {
|
class Storage {
|
||||||
@ -45,7 +46,8 @@ public:
|
|||||||
Storage(const Storage &) = delete;
|
Storage(const Storage &) = delete;
|
||||||
virtual ~Storage() {}
|
virtual ~Storage() {}
|
||||||
|
|
||||||
virtual bool GetInfo(const char *uri_utf8, bool follow, FileInfo &info,
|
virtual bool GetInfo(const char *uri_utf8, bool follow,
|
||||||
|
StorageFileInfo &info,
|
||||||
Error &error) = 0;
|
Error &error) = 0;
|
||||||
|
|
||||||
virtual StorageDirectoryReader *OpenDirectory(const char *uri_utf8,
|
virtual StorageDirectoryReader *OpenDirectory(const char *uri_utf8,
|
||||||
|
@ -46,7 +46,8 @@ public:
|
|||||||
|
|
||||||
/* virtual methods from class StorageDirectoryReader */
|
/* virtual methods from class StorageDirectoryReader */
|
||||||
const char *Read() override;
|
const char *Read() override;
|
||||||
bool GetInfo(bool follow, FileInfo &info, Error &error) override;
|
bool GetInfo(bool follow, StorageFileInfo &info,
|
||||||
|
Error &error) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LocalStorage final : public Storage {
|
class LocalStorage final : public Storage {
|
||||||
@ -61,7 +62,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* virtual methods from class Storage */
|
/* virtual methods from class Storage */
|
||||||
bool GetInfo(const char *uri_utf8, bool follow, FileInfo &info,
|
bool GetInfo(const char *uri_utf8, bool follow, StorageFileInfo &info,
|
||||||
Error &error) override;
|
Error &error) override;
|
||||||
|
|
||||||
StorageDirectoryReader *OpenDirectory(const char *uri_utf8,
|
StorageDirectoryReader *OpenDirectory(const char *uri_utf8,
|
||||||
@ -78,7 +79,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
Stat(Path path, bool follow, FileInfo &info, Error &error)
|
Stat(Path path, bool follow, StorageFileInfo &info, Error &error)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if (!StatFile(path, st, follow)) {
|
if (!StatFile(path, st, follow)) {
|
||||||
@ -90,11 +91,11 @@ Stat(Path path, bool follow, FileInfo &info, Error &error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (S_ISREG(st.st_mode))
|
if (S_ISREG(st.st_mode))
|
||||||
info.type = FileInfo::Type::REGULAR;
|
info.type = StorageFileInfo::Type::REGULAR;
|
||||||
else if (S_ISDIR(st.st_mode))
|
else if (S_ISDIR(st.st_mode))
|
||||||
info.type = FileInfo::Type::DIRECTORY;
|
info.type = StorageFileInfo::Type::DIRECTORY;
|
||||||
else
|
else
|
||||||
info.type = FileInfo::Type::OTHER;
|
info.type = StorageFileInfo::Type::OTHER;
|
||||||
|
|
||||||
info.size = st.st_size;
|
info.size = st.st_size;
|
||||||
info.mtime = st.st_mtime;
|
info.mtime = st.st_mtime;
|
||||||
@ -142,7 +143,7 @@ LocalStorage::MapToRelativeUTF8(const char *uri_utf8) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
LocalStorage::GetInfo(const char *uri_utf8, bool follow, FileInfo &info,
|
LocalStorage::GetInfo(const char *uri_utf8, bool follow, StorageFileInfo &info,
|
||||||
Error &error)
|
Error &error)
|
||||||
{
|
{
|
||||||
AllocatedPath path_fs = MapFS(uri_utf8, error);
|
AllocatedPath path_fs = MapFS(uri_utf8, error);
|
||||||
@ -198,7 +199,7 @@ LocalDirectoryReader::Read()
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
LocalDirectoryReader::GetInfo(bool follow, FileInfo &info, Error &error)
|
LocalDirectoryReader::GetInfo(bool follow, StorageFileInfo &info, Error &error)
|
||||||
{
|
{
|
||||||
const AllocatedPath path_fs =
|
const AllocatedPath path_fs =
|
||||||
AllocatedPath::Build(base_fs, reader.GetEntry());
|
AllocatedPath::Build(base_fs, reader.GetEntry());
|
||||||
|
@ -84,7 +84,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* virtual methods from class Storage */
|
/* virtual methods from class Storage */
|
||||||
bool GetInfo(const char *uri_utf8, bool follow, FileInfo &info,
|
bool GetInfo(const char *uri_utf8, bool follow, StorageFileInfo &info,
|
||||||
Error &error) override;
|
Error &error) override;
|
||||||
|
|
||||||
StorageDirectoryReader *OpenDirectory(const char *uri_utf8,
|
StorageDirectoryReader *OpenDirectory(const char *uri_utf8,
|
||||||
@ -245,14 +245,14 @@ NfsStorage::MapToRelativeUTF8(const char *uri_utf8) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
Copy(FileInfo &info, const struct stat &st)
|
Copy(StorageFileInfo &info, const struct stat &st)
|
||||||
{
|
{
|
||||||
if (S_ISREG(st.st_mode))
|
if (S_ISREG(st.st_mode))
|
||||||
info.type = FileInfo::Type::REGULAR;
|
info.type = StorageFileInfo::Type::REGULAR;
|
||||||
else if (S_ISDIR(st.st_mode))
|
else if (S_ISDIR(st.st_mode))
|
||||||
info.type = FileInfo::Type::DIRECTORY;
|
info.type = StorageFileInfo::Type::DIRECTORY;
|
||||||
else
|
else
|
||||||
info.type = FileInfo::Type::OTHER;
|
info.type = StorageFileInfo::Type::OTHER;
|
||||||
|
|
||||||
info.size = st.st_size;
|
info.size = st.st_size;
|
||||||
info.mtime = st.st_mtime;
|
info.mtime = st.st_mtime;
|
||||||
@ -262,11 +262,11 @@ Copy(FileInfo &info, const struct stat &st)
|
|||||||
|
|
||||||
class NfsGetInfoOperation final : public BlockingNfsOperation {
|
class NfsGetInfoOperation final : public BlockingNfsOperation {
|
||||||
const char *const path;
|
const char *const path;
|
||||||
FileInfo &info;
|
StorageFileInfo &info;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NfsGetInfoOperation(NfsConnection &_connection, const char *_path,
|
NfsGetInfoOperation(NfsConnection &_connection, const char *_path,
|
||||||
FileInfo &_info)
|
StorageFileInfo &_info)
|
||||||
:BlockingNfsOperation(_connection), path(_path), info(_info) {}
|
:BlockingNfsOperation(_connection), path(_path), info(_info) {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -281,7 +281,7 @@ protected:
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
NfsStorage::GetInfo(const char *uri_utf8, gcc_unused bool follow,
|
NfsStorage::GetInfo(const char *uri_utf8, gcc_unused bool follow,
|
||||||
FileInfo &info, Error &error)
|
StorageFileInfo &info, Error &error)
|
||||||
{
|
{
|
||||||
const std::string path = UriToNfsPath(uri_utf8, error);
|
const std::string path = UriToNfsPath(uri_utf8, error);
|
||||||
if (path.empty())
|
if (path.empty())
|
||||||
@ -304,19 +304,19 @@ SkipNameFS(const char *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
Copy(FileInfo &info, const struct nfsdirent &ent)
|
Copy(StorageFileInfo &info, const struct nfsdirent &ent)
|
||||||
{
|
{
|
||||||
switch (ent.type) {
|
switch (ent.type) {
|
||||||
case NF3REG:
|
case NF3REG:
|
||||||
info.type = FileInfo::Type::REGULAR;
|
info.type = StorageFileInfo::Type::REGULAR;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NF3DIR:
|
case NF3DIR:
|
||||||
info.type = FileInfo::Type::DIRECTORY;
|
info.type = StorageFileInfo::Type::DIRECTORY;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
info.type = FileInfo::Type::OTHER;
|
info.type = StorageFileInfo::Type::OTHER;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,8 @@ public:
|
|||||||
|
|
||||||
/* virtual methods from class StorageDirectoryReader */
|
/* virtual methods from class StorageDirectoryReader */
|
||||||
const char *Read() override;
|
const char *Read() override;
|
||||||
bool GetInfo(bool follow, FileInfo &info, Error &error) override;
|
bool GetInfo(bool follow, StorageFileInfo &info,
|
||||||
|
Error &error) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SmbclientStorage final : public Storage {
|
class SmbclientStorage final : public Storage {
|
||||||
@ -63,7 +64,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* virtual methods from class Storage */
|
/* virtual methods from class Storage */
|
||||||
bool GetInfo(const char *uri_utf8, bool follow, FileInfo &info,
|
bool GetInfo(const char *uri_utf8, bool follow, StorageFileInfo &info,
|
||||||
Error &error) override;
|
Error &error) override;
|
||||||
|
|
||||||
StorageDirectoryReader *OpenDirectory(const char *uri_utf8,
|
StorageDirectoryReader *OpenDirectory(const char *uri_utf8,
|
||||||
@ -92,7 +93,7 @@ SmbclientStorage::MapToRelativeUTF8(const char *uri_utf8) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
GetInfo(const char *path, FileInfo &info, Error &error)
|
GetInfo(const char *path, StorageFileInfo &info, Error &error)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
smbclient_mutex.lock();
|
smbclient_mutex.lock();
|
||||||
@ -104,11 +105,11 @@ GetInfo(const char *path, FileInfo &info, Error &error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (S_ISREG(st.st_mode))
|
if (S_ISREG(st.st_mode))
|
||||||
info.type = FileInfo::Type::REGULAR;
|
info.type = StorageFileInfo::Type::REGULAR;
|
||||||
else if (S_ISDIR(st.st_mode))
|
else if (S_ISDIR(st.st_mode))
|
||||||
info.type = FileInfo::Type::DIRECTORY;
|
info.type = StorageFileInfo::Type::DIRECTORY;
|
||||||
else
|
else
|
||||||
info.type = FileInfo::Type::OTHER;
|
info.type = StorageFileInfo::Type::OTHER;
|
||||||
|
|
||||||
info.size = st.st_size;
|
info.size = st.st_size;
|
||||||
info.mtime = st.st_mtime;
|
info.mtime = st.st_mtime;
|
||||||
@ -119,7 +120,7 @@ GetInfo(const char *path, FileInfo &info, Error &error)
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
SmbclientStorage::GetInfo(const char *uri_utf8, gcc_unused bool follow,
|
SmbclientStorage::GetInfo(const char *uri_utf8, gcc_unused bool follow,
|
||||||
FileInfo &info, Error &error)
|
StorageFileInfo &info, Error &error)
|
||||||
{
|
{
|
||||||
const std::string mapped = MapUTF8(uri_utf8);
|
const std::string mapped = MapUTF8(uri_utf8);
|
||||||
return ::GetInfo(mapped.c_str(), info, error);
|
return ::GetInfo(mapped.c_str(), info, error);
|
||||||
@ -172,7 +173,8 @@ SmbclientDirectoryReader::Read()
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SmbclientDirectoryReader::GetInfo(gcc_unused bool follow, FileInfo &info,
|
SmbclientDirectoryReader::GetInfo(gcc_unused bool follow,
|
||||||
|
StorageFileInfo &info,
|
||||||
Error &error)
|
Error &error)
|
||||||
{
|
{
|
||||||
const std::string path = PathTraitsUTF8::Build(base.c_str(), name);
|
const std::string path = PathTraitsUTF8::Build(base.c_str(), name);
|
||||||
|
@ -56,7 +56,7 @@ Ls(Storage &storage, const char *path)
|
|||||||
|
|
||||||
const char *name;
|
const char *name;
|
||||||
while ((name = dir->Read()) != nullptr) {
|
while ((name = dir->Read()) != nullptr) {
|
||||||
FileInfo info;
|
StorageFileInfo info;
|
||||||
if (!dir->GetInfo(false, info, error)) {
|
if (!dir->GetInfo(false, info, error)) {
|
||||||
printf("Error on %s: %s\n", name, error.GetMessage());
|
printf("Error on %s: %s\n", name, error.GetMessage());
|
||||||
error.Clear();
|
error.Clear();
|
||||||
@ -65,15 +65,15 @@ Ls(Storage &storage, const char *path)
|
|||||||
|
|
||||||
const char *type = "unk";
|
const char *type = "unk";
|
||||||
switch (info.type) {
|
switch (info.type) {
|
||||||
case FileInfo::Type::OTHER:
|
case StorageFileInfo::Type::OTHER:
|
||||||
type = "oth";
|
type = "oth";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FileInfo::Type::REGULAR:
|
case StorageFileInfo::Type::REGULAR:
|
||||||
type = "reg";
|
type = "reg";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FileInfo::Type::DIRECTORY:
|
case StorageFileInfo::Type::DIRECTORY:
|
||||||
type = "dir";
|
type = "dir";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user