rsync: add integrity information

This commit is contained in:
Girish Ramakrishnan
2025-08-13 09:39:36 +05:30
parent 28ac9e153e
commit 2fabfbe8f6
4 changed files with 49 additions and 31 deletions

View File

@@ -62,15 +62,14 @@ function ISFILE(x) {
return (x & fs.constants.S_IFREG) === fs.constants.S_IFREG;
}
async function sync(dataLayout, options) {
async function sync(dataLayout, cacheFile) {
assert(dataLayout instanceof DataLayout, 'Expecting dataLayout to be a DataLayout');
assert.strictEqual(typeof options, 'object');
assert.strictEqual(typeof cacheFile, 'string');
const addQueue = [], delQueue = []; // separate queues. we have to process the del first and then the add
let curCacheIndex = 0;
const cacheFile = options.cacheFile, newCacheFile = `${options.cacheFile}.new`;
const integrityMap = new Map();
const newCacheFile = `${cacheFile}.new`;
let cache = [];
// if cache is missing or if we crashed/errored in previous run, start out empty. TODO: do a remote listDir and rebuild
@@ -119,6 +118,7 @@ async function sync(dataLayout, options) {
const cachePath = curCacheIndex === cache.length ? null : cache[curCacheIndex].path;
const cacheStat = curCacheIndex === cache.length ? null : cache[curCacheIndex].stat;
integrityMap.set(entryPath, curCacheIndex === cache.length ? null : cache[curCacheIndex].integrity);
if (cachePath === null || cachePath > entryPath) { // new files appeared
if (entryStat.isDirectory()) {
@@ -155,15 +155,14 @@ async function sync(dataLayout, options) {
return {
delQueue,
addQueue,
cacheFile,
newCacheFile
integrityMap
};
}
async function finalize(changes) {
assert.strictEqual(typeof changes, 'object');
async function finalize(cacheFile) {
assert.strictEqual(typeof cacheFile, 'string');
safe.fs.unlinkSync(changes.cacheFile);
if (!safe.fs.renameSync(changes.newCacheFile, changes.cacheFile)) debug('Unable to save new cache file');
const newCacheFile = `${cacheFile}.new`;
safe.fs.unlinkSync(cacheFile);
if (!safe.fs.renameSync(newCacheFile, cacheFile)) debug('Unable to save new cache file');
}