mirror of
https://github.com/usatiuk/backup.git
synced 2025-10-27 01:37:49 +01:00
a bit better but still not optimal
This commit is contained in:
@@ -9,6 +9,5 @@ CommandMount::CommandMount() : Command("mount") {
|
||||
}
|
||||
|
||||
void CommandMount::run(Context ctx) {
|
||||
RepoFS rfs(ctx.repo, ctx.repo->getObjects(Object::ObjectType::Archive).begin()->second, "./hi");
|
||||
rfs.workerFn();
|
||||
RepoFS::start(ctx.repo, "./hi");
|
||||
}
|
||||
|
||||
@@ -103,7 +103,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[0]));
|
||||
auto dest = Serialize::deserialize<Chunk>(ctx.repo->getObject(file.chunks.at(0)));
|
||||
std::filesystem::create_symlink(std::filesystem::u8path(std::string{dest.data.begin(), dest.data.end()}), fullpath);
|
||||
callback(0, 0, 1);
|
||||
return fullpath.u8string();
|
||||
@@ -113,7 +113,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));
|
||||
Chunk c = Serialize::deserialize<Chunk>(ctx.repo->getObject(cid.second));
|
||||
if (!c.data.empty()) {
|
||||
ostream.rdbuf()->sputn(c.data.data(), c.data.size());
|
||||
callback(c.data.size(), 0, 0);
|
||||
|
||||
@@ -188,7 +188,7 @@ Object::idType CommandRun::backupChunkFile(const std::filesystem::path &orig, co
|
||||
if (std::filesystem::is_symlink(orig) || std::filesystem::is_directory(orig)) {
|
||||
auto contents = File::getFileContents(orig);
|
||||
Chunk c(ctx.repo->getId(), SHA::calculate(contents), contents);
|
||||
File f(ctx.repo->getId(), saveAs, c.length, File::getFileMtime(orig), c.SHA, {c.id}, File::getFileType(orig));
|
||||
File f(ctx.repo->getId(), saveAs, c.length, File::getFileMtime(orig), c.SHA, {{0, c.id}}, File::getFileType(orig));
|
||||
ctx.repo->putObject(c);
|
||||
ctx.repo->putObject(f);
|
||||
return f.id;
|
||||
@@ -202,7 +202,7 @@ Object::idType CommandRun::backupChunkFile(const std::filesystem::path &orig, co
|
||||
|
||||
SHA fileHash;
|
||||
|
||||
std::vector<Object::idType> fileChunks;
|
||||
std::map<size_t, Object::idType> fileChunks;
|
||||
unsigned long long size = 0;
|
||||
|
||||
for (auto chunkp: *chunker) {
|
||||
@@ -210,7 +210,6 @@ Object::idType CommandRun::backupChunkFile(const std::filesystem::path &orig, co
|
||||
if (Signals::shouldQuit) break;
|
||||
|
||||
Object::idType chunkId;
|
||||
size += chunkp.second.size();
|
||||
if (ctx.repo->getConfig().getStr("dedup") == "on" && ctx.repo->exists(Object::ObjectType::Chunk, chunkp.first)) {
|
||||
/// If the chunk already exists, reuse it
|
||||
chunkId = ctx.repo->getObjectId(Object::ObjectType::Chunk, chunkp.first);
|
||||
@@ -223,7 +222,8 @@ Object::idType CommandRun::backupChunkFile(const std::filesystem::path &orig, co
|
||||
ctx.repo->putObject(c);
|
||||
}
|
||||
fileHash.feedData(chunkp.second);
|
||||
fileChunks.emplace_back(chunkId);
|
||||
fileChunks.emplace(size, chunkId);
|
||||
size += chunkp.second.size();
|
||||
}
|
||||
|
||||
/// We might have exited in the loop before, so we don't save an incomplete file
|
||||
|
||||
Reference in New Issue
Block a user