Commit 699d2d76 authored by Paweł Wegner's avatar Paweł Wegner

Replace std::vector<INode::Pointer> with INode::List.

parent 8f75bc24
...@@ -16,18 +16,13 @@ class IFileSystem { ...@@ -16,18 +16,13 @@ class IFileSystem {
using FileId = uint64_t; using FileId = uint64_t;
using Pointer = std::unique_ptr<IFileSystem>; using Pointer = std::unique_ptr<IFileSystem>;
using ListDirectoryCallback =
std::function<void(EitherError<std::vector<std::shared_ptr<INode>>>)>;
using GetItemCallback = std::function<void(EitherError<INode>)>;
using DownloadItemCallback = std::function<void(EitherError<std::string>)>;
using WriteDataCallback = std::function<void(EitherError<uint32_t>)>;
using DataSynchronizedCallback = std::function<void(EitherError<void>)>;
static constexpr int NotEmpty = 1001; static constexpr int NotEmpty = 1001;
class INode { class INode {
public: public:
using Pointer = std::shared_ptr<INode>; using Pointer = std::shared_ptr<INode>;
using List = std::vector<std::shared_ptr<INode>>;
virtual ~INode() = default; virtual ~INode() = default;
...@@ -38,6 +33,12 @@ class IFileSystem { ...@@ -38,6 +33,12 @@ class IFileSystem {
virtual IItem::FileType type() const = 0; virtual IItem::FileType type() const = 0;
}; };
using ListDirectoryCallback = std::function<void(EitherError<INode::List>)>;
using GetItemCallback = std::function<void(EitherError<INode>)>;
using DownloadItemCallback = std::function<void(EitherError<std::string>)>;
using WriteDataCallback = std::function<void(EitherError<uint32_t>)>;
using DataSynchronizedCallback = std::function<void(EitherError<void>)>;
struct ProviderEntry { struct ProviderEntry {
std::string label_; std::string label_;
std::shared_ptr<ICloudProvider> provider_; std::shared_ptr<ICloudProvider> provider_;
......
...@@ -228,7 +228,7 @@ FileSystem::Node::Pointer FileSystem::get(FileId node) { ...@@ -228,7 +228,7 @@ FileSystem::Node::Pointer FileSystem::get(FileId node) {
void FileSystem::lookup(FileId parent_node, const std::string& name, void FileSystem::lookup(FileId parent_node, const std::string& name,
GetItemCallback cb) { GetItemCallback cb) {
readdir(parent_node, [=](EitherError<std::vector<INode::Pointer>> e) { readdir(parent_node, [=](EitherError<INode::List> e) {
if (auto lst = e.right()) { if (auto lst = e.right()) {
for (auto&& i : *lst) for (auto&& i : *lst)
if (this->sanitize(i->filename()) == name) return cb(i); if (this->sanitize(i->filename()) == name) return cb(i);
...@@ -338,7 +338,7 @@ void FileSystem::readdir(FileId node, ListDirectoryCallback cb) { ...@@ -338,7 +338,7 @@ void FileSystem::readdir(FileId node, ListDirectoryCallback cb) {
CACHE_DIRECTORY_DURATION)) { CACHE_DIRECTORY_DURATION)) {
auto it = node_directory_.find(node); auto it = node_directory_.find(node);
if (it != std::end(node_directory_)) { if (it != std::end(node_directory_)) {
std::vector<INode::Pointer> ret; INode::List ret;
for (auto&& r : it->second) ret.push_back(get(r)); for (auto&& r : it->second) ret.push_back(get(r));
return cb(ret); return cb(ret);
} }
...@@ -357,12 +357,12 @@ void FileSystem::readdir(FileId node, ListDirectoryCallback cb) { ...@@ -357,12 +357,12 @@ void FileSystem::readdir(FileId node, ListDirectoryCallback cb) {
node_directory_[node] = ret; node_directory_[node] = ret;
node_timestamp_[node] = std::chrono::system_clock::now(); node_timestamp_[node] = std::chrono::system_clock::now();
} }
std::vector<INode::Pointer> nodes; INode::List nodes;
for (auto&& r : ret) nodes.push_back(this->get(r)); for (auto&& r : ret) nodes.push_back(this->get(r));
cb(nodes); cb(nodes);
} else { } else {
auto item = auth_item(nd->provider()->authorizeLibraryUrl()); auto item = auth_item(nd->provider()->authorizeLibraryUrl());
cb(std::vector<INode::Pointer>( cb(INode::List(
1, std::make_shared<Node>(nd->provider(), item, node, 1, std::make_shared<Node>(nd->provider(), item, node,
auth_node_[nd->provider()->name()], auth_node_[nd->provider()->name()],
item->size()))); item->size())));
...@@ -532,13 +532,11 @@ void FileSystem::remove(FileId parent, const char* name, ...@@ -532,13 +532,11 @@ void FileSystem::remove(FileId parent, const char* name,
if (e.left()) return callback(e.left()); if (e.left()) return callback(e.left());
auto node = std::static_pointer_cast<Node>(e.right()); auto node = std::static_pointer_cast<Node>(e.right());
if (node->type() == IItem::FileType::Directory) { if (node->type() == IItem::FileType::Directory) {
this->readdir(node->inode(), this->readdir(node->inode(), [=](EitherError<INode::List> e) {
[=](EitherError<std::vector<INode::Pointer>> e) { if (e.left()) return callback(e.left());
if (e.left()) return callback(e.left()); if (!e.right()->empty()) return callback(Error{NotEmpty, "not empty"});
if (!e.right()->empty()) remove_file(node);
return callback(Error{NotEmpty, "not empty"}); });
remove_file(node);
});
} else } else
remove_file(node); remove_file(node);
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment