mirror of
https://github.com/usatiuk/backup.git
synced 2025-10-27 01:37:49 +01:00
sembackup: use sha
This commit is contained in:
@@ -18,7 +18,7 @@ namespace CommandsCommon {
|
||||
/// \param ignore List of files to ignore
|
||||
/// \param spawner Function to spawn other tasks
|
||||
/// \param processFile Task to spawn on found files
|
||||
void processDirWithIgnore(const std::filesystem::path &dir, std::vector<std::string> ignore, std::function<void(std::function<void()>)> spawner, std::function<void(std::filesystem::directory_entry)> processFile);
|
||||
void processDirWithIgnore(const std::filesystem::path &dir, std::vector<std::string> ignore, const std::function<void(std::function<void()>)> &spawner, std::function<void(std::filesystem::directory_entry)> processFile);
|
||||
|
||||
struct WorkerStats {
|
||||
public:
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
#include "../../change_detectors/includes/ChangeDetectorFactory.h"
|
||||
#include "../../chunkers/includes/ChunkerFactory.h"
|
||||
#include "../../crypto/includes/MD5.h"
|
||||
#include "../../crypto/includes/SHA.h"
|
||||
#include "../../repo/includes/Serialize.h"
|
||||
#include "../../repo/includes/objects/Archive.h"
|
||||
#include "../../repo/includes/objects/Chunk.h"
|
||||
@@ -187,8 +187,8 @@ Object::idType CommandRun::backupChunkFile(const std::filesystem::path &orig, co
|
||||
/// The order of checks is important, because is_directory follows the symlink
|
||||
if (std::filesystem::is_symlink(orig) || std::filesystem::is_directory(orig)) {
|
||||
auto contents = File::getFileContents(orig);
|
||||
Chunk c(ctx.repo->getId(), MD5::calculate(contents), contents);
|
||||
File f(ctx.repo->getId(), saveAs, c.length, File::getFileMtime(orig), c.md5, {c.id}, File::getFileType(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));
|
||||
ctx.repo->putObject(c);
|
||||
ctx.repo->putObject(f);
|
||||
return f.id;
|
||||
@@ -200,7 +200,7 @@ Object::idType CommandRun::backupChunkFile(const std::filesystem::path &orig, co
|
||||
if (!ifstream) throw Exception("Couldn't open " + orig.u8string() + " for reading");
|
||||
std::unique_ptr<Chunker> chunker = ChunkerFactory::getChunker(ctx.repo->getConfig(), ifstream.rdbuf());
|
||||
|
||||
MD5 fileHash;
|
||||
SHA fileHash;
|
||||
|
||||
std::vector<Object::idType> fileChunks;
|
||||
unsigned long long size = 0;
|
||||
|
||||
@@ -23,7 +23,7 @@ bool CommandsCommon::isSubpath(const std::filesystem::path &prefix, const std::f
|
||||
return true;
|
||||
}
|
||||
|
||||
void CommandsCommon::processDirWithIgnore(const std::filesystem::path &dir, std::vector<std::string> ignore, std::function<void(std::function<void()>)> spawner, std::function<void(std::filesystem::directory_entry)> processFile) {
|
||||
void CommandsCommon::processDirWithIgnore(const std::filesystem::path &dir, std::vector<std::string> ignore, const std::function<void(std::function<void()>)> &spawner, std::function<void(std::filesystem::directory_entry)> processFile) {
|
||||
if (!std::filesystem::is_directory(dir)) throw Exception(dir.u8string() + " is not a directory!");
|
||||
|
||||
/// Don't process the directory if it has a ".nobackup" file
|
||||
|
||||
@@ -74,20 +74,20 @@ std::string Diff::diffPercent(const ComparableFile &c1, const ComparableFile &c2
|
||||
/// Exit when asked to
|
||||
if (Signals::shouldQuit) throw Exception("Quitting");
|
||||
if (chunkp.second.empty()) continue;
|
||||
std::string md5(chunkp.first.begin(), chunkp.first.end());
|
||||
ch1hashes.emplace(md5);
|
||||
hashsize[md5] = chunkp.second.size();
|
||||
std::string SHA(chunkp.first.begin(), chunkp.first.end());
|
||||
ch1hashes.emplace(SHA);
|
||||
hashsize[SHA] = chunkp.second.size();
|
||||
}
|
||||
|
||||
for (auto chunkp: ch2) {
|
||||
/// Exit when asked to
|
||||
if (Signals::shouldQuit) throw Exception("Quitting");
|
||||
if (chunkp.second.empty()) continue;
|
||||
std::string md5(chunkp.first.begin(), chunkp.first.end());
|
||||
hashsize[md5] = chunkp.second.size();
|
||||
if (ch1hashes.count(md5) > 0) ch1hashes.erase(md5);
|
||||
else if (ch1hashes.count(md5) == 0)
|
||||
ch2diff.emplace(md5);
|
||||
std::string SHA(chunkp.first.begin(), chunkp.first.end());
|
||||
hashsize[SHA] = chunkp.second.size();
|
||||
if (ch1hashes.count(SHA) > 0) ch1hashes.erase(SHA);
|
||||
else if (ch1hashes.count(SHA) == 0)
|
||||
ch2diff.emplace(SHA);
|
||||
}
|
||||
|
||||
unsigned long long diff = 0;
|
||||
|
||||
Reference in New Issue
Block a user