mirror of
https://github.com/usatiuk/backup.git
synced 2025-10-26 09:27:48 +01:00
getObject => getObjectRaw
This commit is contained in:
@@ -38,11 +38,11 @@ void CommandDiff::run(Context ctx) {
|
|||||||
ctx.repo->getConfig().exists("threads") ? ctx.repo->getConfig().getInt("threads")
|
ctx.repo->getConfig().exists("threads") ? ctx.repo->getConfig().getInt("threads")
|
||||||
: std::thread::hardware_concurrency());
|
: std::thread::hardware_concurrency());
|
||||||
|
|
||||||
auto archiveO1 = Serialize::deserialize<Archive>(ctx.repo->getObject(archive1));
|
auto archiveO1 = Serialize::deserialize<Archive>(ctx.repo->getObjectRaw(archive1));
|
||||||
std::mutex filesLock;
|
std::mutex filesLock;
|
||||||
std::map<std::filesystem::path, File> files;///< Files in the first archive
|
std::map<std::filesystem::path, File> files;///< Files in the first archive
|
||||||
for (auto id: archiveO1.files) {
|
for (auto id: archiveO1.files) {
|
||||||
auto file = Serialize::deserialize<File>(ctx.repo->getObject(id));
|
auto file = Serialize::deserialize<File>(ctx.repo->getObjectRaw(id));
|
||||||
auto path = std::filesystem::path(file.name);
|
auto path = std::filesystem::path(file.name);
|
||||||
if (isSubpath(ctx.repo->getConfig().getStr("prefix"), path)) files.emplace(file.getKey(), std::move(file));
|
if (isSubpath(ctx.repo->getConfig().getStr("prefix"), path)) files.emplace(file.getKey(), std::move(file));
|
||||||
}
|
}
|
||||||
@@ -76,13 +76,13 @@ void CommandDiff::run(Context ctx) {
|
|||||||
/// If a second archive is given, run the task for each of its files, otherwise use the "from" config option
|
/// If a second archive is given, run the task for each of its files, otherwise use the "from" config option
|
||||||
if (ctx.repo->getConfig().exists("aid2")) {
|
if (ctx.repo->getConfig().exists("aid2")) {
|
||||||
archiveO2.emplace(
|
archiveO2.emplace(
|
||||||
Serialize::deserialize<Archive>(ctx.repo->getObject(ctx.repo->getConfig().getInt("aid2"))));
|
Serialize::deserialize<Archive>(ctx.repo->getObjectRaw(ctx.repo->getConfig().getInt("aid2"))));
|
||||||
|
|
||||||
threadPool.push([&]() {
|
threadPool.push([&]() {
|
||||||
for (auto id: archiveO2.value().files) {
|
for (auto id: archiveO2.value().files) {
|
||||||
/// Exit when asked to
|
/// Exit when asked to
|
||||||
if (Signals::shouldQuit) throw Exception("Quitting");
|
if (Signals::shouldQuit) throw Exception("Quitting");
|
||||||
auto file = Serialize::deserialize<File>(ctx.repo->getObject(id));
|
auto file = Serialize::deserialize<File>(ctx.repo->getObjectRaw(id));
|
||||||
if (isSubpath(ctx.repo->getConfig().getStr("prefix"), std::filesystem::path(file.name)))
|
if (isSubpath(ctx.repo->getConfig().getStr("prefix"), std::filesystem::path(file.name)))
|
||||||
threadPool.push([&, file]() { processFile(ComparableFile{file, ctx.repo}); });
|
threadPool.push([&, file]() { processFile(ComparableFile{file, ctx.repo}); });
|
||||||
if (Signals::shouldQuit) break;
|
if (Signals::shouldQuit) break;
|
||||||
@@ -111,10 +111,10 @@ void CommandDiff::run(Context ctx) {
|
|||||||
|
|
||||||
if (ctx.repo->getConfig().exists("aid2")) {
|
if (ctx.repo->getConfig().exists("aid2")) {
|
||||||
archiveO2.emplace(
|
archiveO2.emplace(
|
||||||
Serialize::deserialize<Archive>(ctx.repo->getObject(ctx.repo->getConfig().getInt("aid2"))));
|
Serialize::deserialize<Archive>(ctx.repo->getObjectRaw(ctx.repo->getConfig().getInt("aid2"))));
|
||||||
std::map<std::filesystem::path, File> files2;///< Files in the first archive
|
std::map<std::filesystem::path, File> files2;///< Files in the first archive
|
||||||
for (auto id: archiveO2->files) {
|
for (auto id: archiveO2->files) {
|
||||||
auto file = Serialize::deserialize<File>(ctx.repo->getObject(id));
|
auto file = Serialize::deserialize<File>(ctx.repo->getObjectRaw(id));
|
||||||
auto path = std::filesystem::path(file.name);
|
auto path = std::filesystem::path(file.name);
|
||||||
if (isSubpath(ctx.repo->getConfig().getStr("prefix"), path))
|
if (isSubpath(ctx.repo->getConfig().getStr("prefix"), path))
|
||||||
files2.emplace(file.getKey(), std::move(file));
|
files2.emplace(file.getKey(), std::move(file));
|
||||||
|
|||||||
@@ -13,9 +13,9 @@
|
|||||||
CommandListFiles::CommandListFiles() : Command() {}
|
CommandListFiles::CommandListFiles() : Command() {}
|
||||||
|
|
||||||
void CommandListFiles::run(Context ctx) {
|
void CommandListFiles::run(Context ctx) {
|
||||||
auto archive = Serialize::deserialize<Archive>(ctx.repo->getObject(ctx.repo->getConfig().getInt("aid")));
|
auto archive = Serialize::deserialize<Archive>(ctx.repo->getObjectRaw(ctx.repo->getConfig().getInt("aid")));
|
||||||
for (auto const &fid: archive.files) {
|
for (auto const &fid: archive.files) {
|
||||||
auto file = Serialize::deserialize<File>(ctx.repo->getObject(fid));
|
auto file = Serialize::deserialize<File>(ctx.repo->getObjectRaw(fid));
|
||||||
std::cout << "Name: " << file.name << " type: " << File::TypeToStr.at(file.fileType)
|
std::cout << "Name: " << file.name << " type: " << File::TypeToStr.at(file.fileType)
|
||||||
<< " size: " << BytesFormatter::formatStr(file.bytes) << std::endl;
|
<< " size: " << BytesFormatter::formatStr(file.bytes) << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,14 +68,14 @@ void CommandRestore::run(Context ctx) {
|
|||||||
/// Add the main restore task
|
/// Add the main restore task
|
||||||
threadPool.push([&, this]() {
|
threadPool.push([&, this]() {
|
||||||
/// Get the archive and its file IDs
|
/// Get the archive and its file IDs
|
||||||
auto archiveO = Serialize::deserialize<Archive>(ctx.repo->getObject(archive));
|
auto archiveO = Serialize::deserialize<Archive>(ctx.repo->getObjectRaw(archive));
|
||||||
std::vector<Object::idType> files = archiveO.files;
|
std::vector<Object::idType> files = archiveO.files;
|
||||||
/// For each file...
|
/// For each file...
|
||||||
for (const auto fid: files) {
|
for (const auto fid: files) {
|
||||||
/// Stop when asked to
|
/// Stop when asked to
|
||||||
if (Signals::shouldQuit) break;
|
if (Signals::shouldQuit) break;
|
||||||
|
|
||||||
auto file = Serialize::deserialize<File>(ctx.repo->getObject(fid));
|
auto file = Serialize::deserialize<File>(ctx.repo->getObjectRaw(fid));
|
||||||
filesToRestoreCount++;
|
filesToRestoreCount++;
|
||||||
bytesToRestore += file.bytes;
|
bytesToRestore += file.bytes;
|
||||||
/// Spawn a restore task
|
/// Spawn a restore task
|
||||||
@@ -105,7 +105,7 @@ std::string CommandRestore::backupRestoreFile(const File &file, const std::files
|
|||||||
return fullpath.string();
|
return fullpath.string();
|
||||||
}
|
}
|
||||||
if (file.fileType == File::Type::Symlink) {
|
if (file.fileType == File::Type::Symlink) {
|
||||||
auto dest = Serialize::deserialize<Chunk>(ctx.repo->getObject(file.chunks.at(0)));
|
auto dest = Serialize::deserialize<Chunk>(ctx.repo->getObjectRaw(file.chunks.at(0)));
|
||||||
std::filesystem::create_symlink(std::filesystem::path(std::string{dest.data.begin(), dest.data.end()}),
|
std::filesystem::create_symlink(std::filesystem::path(std::string{dest.data.begin(), dest.data.end()}),
|
||||||
fullpath);
|
fullpath);
|
||||||
callback(0, 0, 1);
|
callback(0, 0, 1);
|
||||||
@@ -116,7 +116,7 @@ std::string CommandRestore::backupRestoreFile(const File &file, const std::files
|
|||||||
for (const auto cid: file.chunks) {
|
for (const auto cid: file.chunks) {
|
||||||
if (Signals::shouldQuit) throw Exception("Quitting!");
|
if (Signals::shouldQuit) throw Exception("Quitting!");
|
||||||
|
|
||||||
Chunk c = Serialize::deserialize<Chunk>(ctx.repo->getObject(cid.second));
|
Chunk c = Serialize::deserialize<Chunk>(ctx.repo->getObjectRaw(cid.second));
|
||||||
if (!c.data.empty()) {
|
if (!c.data.empty()) {
|
||||||
ostream.rdbuf()->sputn(c.data.data(), c.data.size());
|
ostream.rdbuf()->sputn(c.data.data(), c.data.size());
|
||||||
callback(c.data.size(), 0, 0);
|
callback(c.data.size(), 0, 0);
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ void CommandRun::run(Context ctx) {
|
|||||||
auto relPath = p.lexically_relative(from).string();
|
auto relPath = p.lexically_relative(from).string();
|
||||||
|
|
||||||
if (ctx.repo->exists(Object::ObjectType::File, relPath) != 0) {
|
if (ctx.repo->exists(Object::ObjectType::File, relPath) != 0) {
|
||||||
File repoFile = Serialize::deserialize<File>(ctx.repo->getObject(Object::ObjectType::File, relPath));
|
File repoFile = Serialize::deserialize<File>(ctx.repo->getObjectRaw(Object::ObjectType::File, relPath));
|
||||||
if (!changeDetector.check({repoFile, ctx.repo}, {p, from})) {
|
if (!changeDetector.check({repoFile, ctx.repo}, {p, from})) {
|
||||||
addFile(repoFile.id);
|
addFile(repoFile.id);
|
||||||
progress.print("Skipped: " + relPath, 1);
|
progress.print("Skipped: " + relPath, 1);
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ static int rfsRead(const char *path, char *buf, size_t size, off_t offset, struc
|
|||||||
size_t curInBuf = 0;
|
size_t curInBuf = 0;
|
||||||
size_t curInChunk = offset - curchunk->first;
|
size_t curInChunk = offset - curchunk->first;
|
||||||
while (curInBuf < size) {
|
while (curInBuf < size) {
|
||||||
auto chunk = Serialize::deserialize<Chunk>(RepoFS::repo->getObject(curchunk->second));
|
auto chunk = Serialize::deserialize<Chunk>(RepoFS::repo->getObjectRaw(curchunk->second));
|
||||||
size_t read = std::min((size_t) chunk.length - curInChunk, size - curInBuf);
|
size_t read = std::min((size_t) chunk.length - curInChunk, size - curInBuf);
|
||||||
memcpy(buf + curInBuf, chunk.data.data() + curInChunk, read);
|
memcpy(buf + curInBuf, chunk.data.data() + curInChunk, read);
|
||||||
curInBuf += read;
|
curInBuf += read;
|
||||||
@@ -121,7 +121,7 @@ static int rfsReadlink(const char *path, char *buf, size_t size) {
|
|||||||
} catch (...) { return -ENOENT; }
|
} catch (...) { return -ENOENT; }
|
||||||
|
|
||||||
if (entry->file->fileType != File::Type::Symlink) return -ENOENT;
|
if (entry->file->fileType != File::Type::Symlink) return -ENOENT;
|
||||||
auto dst = Serialize::deserialize<Chunk>(RepoFS::repo->getObject(entry->file->chunks.at(0)));
|
auto dst = Serialize::deserialize<Chunk>(RepoFS::repo->getObjectRaw(entry->file->chunks.at(0)));
|
||||||
strncpy(buf, dst.data.data(), std::min(dst.data.size(), size));
|
strncpy(buf, dst.data.data(), std::min(dst.data.size(), size));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -139,9 +139,9 @@ void RepoFS::start(Repository *repo, std::string path) {
|
|||||||
RepoFS::repo = repo;
|
RepoFS::repo = repo;
|
||||||
auto ars = repo->getObjects(Object::ObjectType::Archive);
|
auto ars = repo->getObjects(Object::ObjectType::Archive);
|
||||||
for (auto const &r: ars) {
|
for (auto const &r: ars) {
|
||||||
auto a = Serialize::deserialize<Archive>(repo->getObject(r.second));
|
auto a = Serialize::deserialize<Archive>(repo->getObjectRaw(r.second));
|
||||||
for (auto const &f: a.files) {
|
for (auto const &f: a.files) {
|
||||||
auto file = Serialize::deserialize<File>(repo->getObject(f));
|
auto file = Serialize::deserialize<File>(repo->getObjectRaw(f));
|
||||||
auto path = std::filesystem::path(file.name);
|
auto path = std::filesystem::path(file.name);
|
||||||
DirEntry *entry = root->children[std::to_string(a.id)].get()
|
DirEntry *entry = root->children[std::to_string(a.id)].get()
|
||||||
? root->children[std::to_string(a.id)].get()
|
? root->children[std::to_string(a.id)].get()
|
||||||
|
|||||||
@@ -35,11 +35,11 @@ public:
|
|||||||
bool init() override;
|
bool init() override;
|
||||||
bool flush() override;
|
bool flush() override;
|
||||||
|
|
||||||
std::vector<char> getObject(Object::idType id) const override;
|
std::vector<char> getObjectRaw(Object::idType id) const override;
|
||||||
bool putObject(const Object &obj) override;
|
bool putObject(const Object &obj) override;
|
||||||
bool deleteObject(const Object &obj) override;
|
bool deleteObject(const Object &obj) override;
|
||||||
|
|
||||||
std::vector<char> getObject(Object::ObjectType type, const std::string &key) const override;
|
std::vector<char> getObjectRaw(Object::ObjectType type, const std::string &key) const override;
|
||||||
Object::idType getObjectId(Object::ObjectType type, const std::string &key) const override;
|
Object::idType getObjectId(Object::ObjectType type, const std::string &key) const override;
|
||||||
std::vector<std::pair<std::string, Object::idType>> getObjects(Object::ObjectType type) const override;
|
std::vector<std::pair<std::string, Object::idType>> getObjects(Object::ObjectType type) const override;
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public:
|
|||||||
/// \param id ID of object to return
|
/// \param id ID of object to return
|
||||||
/// \return Serialized object
|
/// \return Serialized object
|
||||||
/// \throws Exception on any error or if object doesn't exist
|
/// \throws Exception on any error or if object doesn't exist
|
||||||
virtual std::vector<char> getObject(Object::idType id) const = 0;
|
virtual std::vector<char> getObjectRaw(Object::idType id) const = 0;
|
||||||
|
|
||||||
/// Adds the Object \p obj to the Repository
|
/// Adds the Object \p obj to the Repository
|
||||||
/// \param obj Constant reference to the object
|
/// \param obj Constant reference to the object
|
||||||
@@ -64,7 +64,7 @@ public:
|
|||||||
/// \param key Constant reference to the key of the object
|
/// \param key Constant reference to the key of the object
|
||||||
/// \return Serialized object
|
/// \return Serialized object
|
||||||
/// \throws Exception on any error or if object doesn't exist
|
/// \throws Exception on any error or if object doesn't exist
|
||||||
virtual std::vector<char> getObject(Object::ObjectType type, const std::string &key) const = 0;
|
virtual std::vector<char> getObjectRaw(Object::ObjectType type, const std::string &key) const = 0;
|
||||||
|
|
||||||
/// Returns the id of an Object of type \p type and with key \p key
|
/// Returns the id of an Object of type \p type and with key \p key
|
||||||
/// \param type Type of the object
|
/// \param type Type of the object
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ FileRepository::~FileRepository() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<char> FileRepository::getObject(Object::idType id) const {
|
std::vector<char> FileRepository::getObjectRaw(Object::idType id) const {
|
||||||
if (!ready) throw Exception("Tried working with uninitialized repo!");
|
if (!ready) throw Exception("Tried working with uninitialized repo!");
|
||||||
|
|
||||||
std::unique_lock lock(repoLock);
|
std::unique_lock lock(repoLock);
|
||||||
@@ -188,8 +188,8 @@ bool FileRepository::writeFile(const std::filesystem::path &file, const std::vec
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<char> FileRepository::getObject(Object::ObjectType type, const std::string &key) const {
|
std::vector<char> FileRepository::getObjectRaw(Object::ObjectType type, const std::string &key) const {
|
||||||
return getObject(getObjectId(type, key));
|
return getObjectRaw(getObjectId(type, key));
|
||||||
}
|
}
|
||||||
|
|
||||||
Object::idType FileRepository::getObjectId(Object::ObjectType type, const std::string &key) const {
|
Object::idType FileRepository::getObjectId(Object::ObjectType type, const std::string &key) const {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
#include "Serialize.h"
|
#include "Serialize.h"
|
||||||
|
|
||||||
FileBuffer::FileBuffer(const Repository *repo, Object::idType fileId)
|
FileBuffer::FileBuffer(const Repository *repo, Object::idType fileId)
|
||||||
: repo(repo), file(Serialize::deserialize<File>(repo->getObject(fileId))), chunksQueue() {
|
: repo(repo), file(Serialize::deserialize<File>(repo->getObjectRaw(fileId))), chunksQueue() {
|
||||||
for (auto const &id: file.chunks) chunksQueue.emplace(id.second);
|
for (auto const &id: file.chunks) chunksQueue.emplace(id.second);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ int FileBuffer::underflow() {
|
|||||||
if (getBuf.empty() || curGetBufPos == getBuf.size()) {
|
if (getBuf.empty() || curGetBufPos == getBuf.size()) {
|
||||||
if (chunksQueue.empty()) return traits_type::eof();
|
if (chunksQueue.empty()) return traits_type::eof();
|
||||||
else {
|
else {
|
||||||
auto chunk = Serialize::deserialize<Chunk>(repo->getObject(chunksQueue.front()));
|
auto chunk = Serialize::deserialize<Chunk>(repo->getObjectRaw(chunksQueue.front()));
|
||||||
getBuf = chunk.data;
|
getBuf = chunk.data;
|
||||||
chunksQueue.pop();
|
chunksQueue.pop();
|
||||||
curGetBufPos = 0;
|
curGetBufPos = 0;
|
||||||
|
|||||||
@@ -48,8 +48,8 @@ TEST(FileRepository, Deserialize) {
|
|||||||
ASSERT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o1k), 666);
|
ASSERT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o1k), 666);
|
||||||
ASSERT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o2k), 777);
|
ASSERT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o2k), 777);
|
||||||
|
|
||||||
auto o1o = repo.getObject(666);
|
auto o1o = repo.getObjectRaw(666);
|
||||||
auto o2o = repo.getObject(777);
|
auto o2o = repo.getObjectRaw(777);
|
||||||
|
|
||||||
auto o1ob = o1o.cbegin();
|
auto o1ob = o1o.cbegin();
|
||||||
auto o2ob = o2o.cbegin();
|
auto o2ob = o2o.cbegin();
|
||||||
@@ -126,7 +126,7 @@ TEST(FileRepository, Filters) {
|
|||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
auto o1o = repo.getObject(666);
|
auto o1o = repo.getObjectRaw(666);
|
||||||
auto o1ob = o1o.cbegin();
|
auto o1ob = o1o.cbegin();
|
||||||
|
|
||||||
Chunk o1(o1ob, o1o.cend());
|
Chunk o1(o1ob, o1o.cend());
|
||||||
@@ -134,7 +134,7 @@ TEST(FileRepository, Filters) {
|
|||||||
} catch (...) {}
|
} catch (...) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
auto o2o = repo.getObject(777);
|
auto o2o = repo.getObjectRaw(777);
|
||||||
auto o2ob = o2o.cbegin();
|
auto o2ob = o2o.cbegin();
|
||||||
|
|
||||||
Chunk o2(o2ob, o2o.cend());
|
Chunk o2(o2ob, o2o.cend());
|
||||||
@@ -163,8 +163,8 @@ TEST(FileRepository, Filters) {
|
|||||||
ASSERT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o1k), 666);
|
ASSERT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o1k), 666);
|
||||||
ASSERT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o2k), 777);
|
ASSERT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o2k), 777);
|
||||||
|
|
||||||
auto o1o = repo.getObject(666);
|
auto o1o = repo.getObjectRaw(666);
|
||||||
auto o2o = repo.getObject(777);
|
auto o2o = repo.getObjectRaw(777);
|
||||||
|
|
||||||
auto o1ob = o1o.cbegin();
|
auto o1ob = o1o.cbegin();
|
||||||
auto o2ob = o2o.cbegin();
|
auto o2ob = o2o.cbegin();
|
||||||
@@ -224,8 +224,8 @@ TEST(FileRepository, IDsDisabled) {
|
|||||||
conf.add("repo", "IDS/testrepo");
|
conf.add("repo", "IDS/testrepo");
|
||||||
FileRepository repo(conf);
|
FileRepository repo(conf);
|
||||||
repo.open();
|
repo.open();
|
||||||
auto o1o = repo.getObject(1);
|
auto o1o = repo.getObjectRaw(1);
|
||||||
auto o2o = repo.getObject(2);
|
auto o2o = repo.getObjectRaw(2);
|
||||||
|
|
||||||
auto o1ob = o1o.cbegin();
|
auto o1ob = o1o.cbegin();
|
||||||
auto o2ob = o2o.cbegin();
|
auto o2ob = o2o.cbegin();
|
||||||
|
|||||||
Reference in New Issue
Block a user