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")
|
||||
: 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::map<std::filesystem::path, File> files;///< Files in the first archive
|
||||
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::u8path(file.name);
|
||||
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 (ctx.repo->getConfig().exists("aid2")) {
|
||||
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([&]() {
|
||||
for (auto id: archiveO2.value().files) {
|
||||
/// Exit when asked to
|
||||
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::u8path(file.name)))
|
||||
threadPool.push([&, file]() { processFile(ComparableFile{file, ctx.repo}); });
|
||||
if (Signals::shouldQuit) break;
|
||||
@@ -111,10 +111,10 @@ void CommandDiff::run(Context ctx) {
|
||||
|
||||
if (ctx.repo->getConfig().exists("aid2")) {
|
||||
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
|
||||
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::u8path(file.name);
|
||||
if (isSubpath(ctx.repo->getConfig().getStr("prefix"), path))
|
||||
files2.emplace(file.getKey(), std::move(file));
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
CommandListFiles::CommandListFiles() : Command() {}
|
||||
|
||||
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) {
|
||||
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)
|
||||
<< " size: " << BytesFormatter::formatStr(file.bytes) << std::endl;
|
||||
}
|
||||
|
||||
@@ -68,14 +68,14 @@ void CommandRestore::run(Context ctx) {
|
||||
/// Add the main restore task
|
||||
threadPool.push([&, this]() {
|
||||
/// 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;
|
||||
/// For each file...
|
||||
for (const auto fid: files) {
|
||||
/// Stop when asked to
|
||||
if (Signals::shouldQuit) break;
|
||||
|
||||
auto file = Serialize::deserialize<File>(ctx.repo->getObject(fid));
|
||||
auto file = Serialize::deserialize<File>(ctx.repo->getObjectRaw(fid));
|
||||
filesToRestoreCount++;
|
||||
bytesToRestore += file.bytes;
|
||||
/// Spawn a restore task
|
||||
@@ -105,7 +105,7 @@ std::string CommandRestore::backupRestoreFile(const File &file, const std::files
|
||||
return fullpath.u8string();
|
||||
}
|
||||
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::u8path(std::string{dest.data.begin(), dest.data.end()}),
|
||||
fullpath);
|
||||
callback(0, 0, 1);
|
||||
@@ -116,7 +116,7 @@ std::string CommandRestore::backupRestoreFile(const File &file, const std::files
|
||||
for (const auto cid: file.chunks) {
|
||||
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()) {
|
||||
ostream.rdbuf()->sputn(c.data.data(), c.data.size());
|
||||
callback(c.data.size(), 0, 0);
|
||||
|
||||
@@ -89,7 +89,7 @@ void CommandRun::run(Context ctx) {
|
||||
auto relPath = p.lexically_relative(from).u8string();
|
||||
|
||||
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})) {
|
||||
addFile(repoFile.id);
|
||||
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 curInChunk = offset - curchunk->first;
|
||||
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);
|
||||
memcpy(buf + curInBuf, chunk.data.data() + curInChunk, read);
|
||||
curInBuf += read;
|
||||
@@ -121,7 +121,7 @@ static int rfsReadlink(const char *path, char *buf, size_t size) {
|
||||
} catch (...) { 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));
|
||||
|
||||
return 0;
|
||||
@@ -139,9 +139,9 @@ void RepoFS::start(Repository *repo, std::string path) {
|
||||
RepoFS::repo = repo;
|
||||
auto ars = repo->getObjects(Object::ObjectType::Archive);
|
||||
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) {
|
||||
auto file = Serialize::deserialize<File>(repo->getObject(f));
|
||||
auto file = Serialize::deserialize<File>(repo->getObjectRaw(f));
|
||||
auto path = std::filesystem::u8path(file.name);
|
||||
DirEntry *entry = 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 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 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;
|
||||
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
|
||||
/// \return Serialized object
|
||||
/// \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
|
||||
/// \param obj Constant reference to the object
|
||||
@@ -64,7 +64,7 @@ public:
|
||||
/// \param key Constant reference to the key of the object
|
||||
/// \return Serialized object
|
||||
/// \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
|
||||
/// \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!");
|
||||
|
||||
std::unique_lock lock(repoLock);
|
||||
@@ -188,8 +188,8 @@ bool FileRepository::writeFile(const std::filesystem::path &file, const std::vec
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<char> FileRepository::getObject(Object::ObjectType type, const std::string &key) const {
|
||||
return getObject(getObjectId(type, key));
|
||||
std::vector<char> FileRepository::getObjectRaw(Object::ObjectType type, const std::string &key) const {
|
||||
return getObjectRaw(getObjectId(type, key));
|
||||
}
|
||||
|
||||
Object::idType FileRepository::getObjectId(Object::ObjectType type, const std::string &key) const {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "Serialize.h"
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
@@ -35,7 +35,7 @@ int FileBuffer::underflow() {
|
||||
if (getBuf.empty() || curGetBufPos == getBuf.size()) {
|
||||
if (chunksQueue.empty()) return traits_type::eof();
|
||||
else {
|
||||
auto chunk = Serialize::deserialize<Chunk>(repo->getObject(chunksQueue.front()));
|
||||
auto chunk = Serialize::deserialize<Chunk>(repo->getObjectRaw(chunksQueue.front()));
|
||||
getBuf = chunk.data;
|
||||
chunksQueue.pop();
|
||||
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, o2k), 777);
|
||||
|
||||
auto o1o = repo.getObject(666);
|
||||
auto o2o = repo.getObject(777);
|
||||
auto o1o = repo.getObjectRaw(666);
|
||||
auto o2o = repo.getObjectRaw(777);
|
||||
|
||||
auto o1ob = o1o.cbegin();
|
||||
auto o2ob = o2o.cbegin();
|
||||
@@ -126,7 +126,7 @@ TEST(FileRepository, Filters) {
|
||||
|
||||
|
||||
try {
|
||||
auto o1o = repo.getObject(666);
|
||||
auto o1o = repo.getObjectRaw(666);
|
||||
auto o1ob = o1o.cbegin();
|
||||
|
||||
Chunk o1(o1ob, o1o.cend());
|
||||
@@ -134,7 +134,7 @@ TEST(FileRepository, Filters) {
|
||||
} catch (...) {}
|
||||
|
||||
try {
|
||||
auto o2o = repo.getObject(777);
|
||||
auto o2o = repo.getObjectRaw(777);
|
||||
auto o2ob = o2o.cbegin();
|
||||
|
||||
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, o2k), 777);
|
||||
|
||||
auto o1o = repo.getObject(666);
|
||||
auto o2o = repo.getObject(777);
|
||||
auto o1o = repo.getObjectRaw(666);
|
||||
auto o2o = repo.getObjectRaw(777);
|
||||
|
||||
auto o1ob = o1o.cbegin();
|
||||
auto o2ob = o2o.cbegin();
|
||||
@@ -224,8 +224,8 @@ TEST(FileRepository, IDsDisabled) {
|
||||
conf.add("repo", "IDS/testrepo");
|
||||
FileRepository repo(conf);
|
||||
repo.open();
|
||||
auto o1o = repo.getObject(1);
|
||||
auto o2o = repo.getObject(2);
|
||||
auto o1o = repo.getObjectRaw(1);
|
||||
auto o2o = repo.getObjectRaw(2);
|
||||
|
||||
auto o1ob = o1o.cbegin();
|
||||
auto o2ob = o2o.cbegin();
|
||||
|
||||
Reference in New Issue
Block a user