diff --git a/src/zimfuse/node.h b/src/zimfuse/node.h index c6f6d8ea..a6dadb17 100644 --- a/src/zimfuse/node.h +++ b/src/zimfuse/node.h @@ -12,6 +12,7 @@ struct Node { Node* parent; std::string fullPath; std::string originalPath; + int collisionCount = 0; std::vector children; void addChild(Node* child) diff --git a/src/zimfuse/tree.cpp b/src/zimfuse/tree.cpp index b8c83b13..636b86cf 100644 --- a/src/zimfuse/tree.cpp +++ b/src/zimfuse/tree.cpp @@ -9,13 +9,18 @@ std::string sanitize(const std::string& name) return name; } -std::pair Tree::attachFile(const std::string& name, Node* parent) +std::pair Tree::attachFile(const std::string& name, Node* parent, int collisionCount = 0) { auto sanitizedName = sanitize(name); + if (collisionCount) + sanitizedName += '(' + std::to_string(collisionCount) + ')'; auto fullPath = parent->fullPath + '/' + sanitizedName; auto originalPath = parent->originalPath + '/' + name; - if (mappedNodes.count(fullPath)) - return {mappedNodes[fullPath].get(), false}; + if (mappedNodes.count(fullPath)) { + auto node = mappedNodes[fullPath].get(); + node->collisionCount++; + return attachFile(name, parent, node->collisionCount); + } auto n = Node::Ptr(new Node{.name = sanitizedName, .isDir = false, diff --git a/src/zimfuse/tree.h b/src/zimfuse/tree.h index 23ef836a..2c775db9 100644 --- a/src/zimfuse/tree.h +++ b/src/zimfuse/tree.h @@ -10,7 +10,7 @@ class Tree public: Tree(const std::string &path); std::pair attachNode(const std::string& path, Node* parent); - std::pair attachFile(const std::string& path, Node* parent); + std::pair attachFile(const std::string& path, Node* parent, int collisionCount); Node* findNode(const std::string& name); zim::Archive* getArchive() { return &zimArchive; } ~Tree();