Merge branch 'v0.21.x'
This commit is contained in:
@@ -211,6 +211,7 @@ CompositeStorage::Mount(const char *uri, std::unique_ptr<Storage> storage)
|
||||
const std::lock_guard<Mutex> protect(mutex);
|
||||
|
||||
Directory &directory = root.Make(uri);
|
||||
assert(!directory.storage);
|
||||
directory.storage = std::move(storage);
|
||||
}
|
||||
|
||||
|
@@ -100,6 +100,15 @@ public:
|
||||
gcc_pure gcc_nonnull_all
|
||||
Storage *GetMount(std::string_view uri) noexcept;
|
||||
|
||||
/**
|
||||
* Is the given URI a mount point, i.e. is something already
|
||||
* mounted on this path?
|
||||
*/
|
||||
gcc_pure gcc_nonnull_all
|
||||
bool IsMountPoint(const char *uri) noexcept {
|
||||
return GetMount(uri) != nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call the given function for each mounted storage, including
|
||||
* the root storage. Passes mount point URI and the a const
|
||||
@@ -112,6 +121,15 @@ public:
|
||||
VisitMounts(uri, root, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is a storage with the given URI already mounted?
|
||||
*/
|
||||
gcc_pure gcc_nonnull_all
|
||||
bool IsMounted(const char *storage_uri) const noexcept {
|
||||
const std::lock_guard<Mutex> protect(mutex);
|
||||
return IsMounted(root, storage_uri);
|
||||
}
|
||||
|
||||
void Mount(const char *uri, std::unique_ptr<Storage> storage);
|
||||
bool Unmount(const char *uri);
|
||||
|
||||
@@ -146,6 +164,22 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
gcc_pure gcc_nonnull_all
|
||||
static bool IsMounted(const Directory &directory,
|
||||
const char *storage_uri) noexcept {
|
||||
if (directory.storage) {
|
||||
const auto uri = directory.storage->MapUTF8("");
|
||||
if (uri == storage_uri)
|
||||
return true;
|
||||
}
|
||||
|
||||
for (const auto &i : directory.children)
|
||||
if (IsMounted(i.second, storage_uri))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Follow the given URI path, and find the outermost directory
|
||||
* which is a #Storage mount point. If there are no mounts,
|
||||
|
@@ -106,6 +106,17 @@ storage_state_restore(const char *line, TextFile &file, Instance &instance)
|
||||
|
||||
FormatDebug(storage_domain, "Restoring mount %s => %s", uri.c_str(), url.c_str());
|
||||
|
||||
auto &composite_storage = *(CompositeStorage *)instance.storage;
|
||||
if (composite_storage.IsMountPoint(uri.c_str())) {
|
||||
LogError(storage_domain, "Mount point busy");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (composite_storage.IsMounted(url.c_str())) {
|
||||
LogError(storage_domain, "This storage is already mounted");
|
||||
return true;
|
||||
}
|
||||
|
||||
auto &event_loop = instance.io_thread.GetEventLoop();
|
||||
auto storage = CreateStorageURI(event_loop, url.c_str());
|
||||
if (storage == nullptr) {
|
||||
@@ -124,8 +135,7 @@ storage_state_restore(const char *line, TextFile &file, Instance &instance)
|
||||
}
|
||||
}
|
||||
|
||||
((CompositeStorage*)instance.storage)->Mount(uri.c_str(),
|
||||
std::move(storage));
|
||||
composite_storage.Mount(uri.c_str(), std::move(storage));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user