mirror of
https://github.com/usatiuk/backup.git
synced 2025-10-26 17:37:47 +01:00
getRefs on objects
This commit is contained in:
@@ -31,6 +31,9 @@ public:
|
|||||||
/// All derived objects should implement this method
|
/// All derived objects should implement this method
|
||||||
virtual std::string getKey() const = 0;
|
virtual std::string getKey() const = 0;
|
||||||
|
|
||||||
|
/// Returns the keys of that this object refers to
|
||||||
|
virtual const std::vector<idType> &getRefs() const;
|
||||||
|
|
||||||
const idType id; ///< Unique numerical of the object
|
const idType id; ///< Unique numerical of the object
|
||||||
const ObjectType type;///< Type of the object
|
const ObjectType type;///< Type of the object
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ public:
|
|||||||
/// Returns the name of the archive
|
/// Returns the name of the archive
|
||||||
std::string getKey() const override;
|
std::string getKey() const override;
|
||||||
|
|
||||||
|
/// Returns the files in this archive
|
||||||
|
const std::vector<Object::idType> &getRefs() const override;
|
||||||
|
|
||||||
const std::string name; ///< Archive name
|
const std::string name; ///< Archive name
|
||||||
const unsigned long long mtime; ///< Time of creation
|
const unsigned long long mtime; ///< Time of creation
|
||||||
const std::vector<idType> files;///< List of ids of File objects in the Archive
|
const std::vector<idType> files;///< List of ids of File objects in the Archive
|
||||||
|
|||||||
@@ -68,6 +68,12 @@ public:
|
|||||||
/// List of the chunks in file
|
/// List of the chunks in file
|
||||||
/// Normal file has normal chunks as its contents, for Directory it's empty, Symlink has a chunk with its target path
|
/// Normal file has normal chunks as its contents, for Directory it's empty, Symlink has a chunk with its target path
|
||||||
const std::map<size_t, idType> chunks;
|
const std::map<size_t, idType> chunks;
|
||||||
|
|
||||||
|
const std::vector<idType> &getRefs() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void makeChunksList() const;
|
||||||
|
mutable std::optional<std::vector<idType>> chunksList{std::nullopt};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -17,3 +17,7 @@ void Object::serialize(std::vector<char> &out) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Object::~Object() = default;
|
Object::~Object() = default;
|
||||||
|
|
||||||
|
static std::vector<Object::idType> emptyRef{};
|
||||||
|
|
||||||
|
const std::vector<Object::idType> &Object::getRefs() const { return emptyRef; }
|
||||||
|
|||||||
@@ -28,3 +28,5 @@ void Archive::serialize(std::vector<char> &out) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string Archive::getKey() const { return name; }
|
std::string Archive::getKey() const { return name; }
|
||||||
|
|
||||||
|
const std::vector<Object::idType> &Archive::getRefs() const { return files; }
|
||||||
|
|||||||
@@ -83,3 +83,16 @@ unsigned long long File::getFileSize(const std::filesystem::path &p) {
|
|||||||
else
|
else
|
||||||
return getFileContents(p).size();
|
return getFileContents(p).size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void File::makeChunksList() const {
|
||||||
|
if (chunksList) return;
|
||||||
|
chunksList.emplace();
|
||||||
|
|
||||||
|
chunksList->reserve(chunks.size());
|
||||||
|
for (auto const &c: chunks) chunksList->emplace_back(c.second);
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<Object::idType> &File::getRefs() const {
|
||||||
|
if (!chunksList) makeChunksList();
|
||||||
|
return *chunksList;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user