diff --git a/src/backups.js b/src/backups.js index aa4dc5a22..f0f5f3632 100644 --- a/src/backups.js +++ b/src/backups.js @@ -257,7 +257,7 @@ function sync(backupConfig, backupId, dataDir, callback) { ++retryCount; debug(`${task.operation} ${task.path} try ${retryCount}`); if (task.operation === 'add') { - setBackupProgress(`Adding ${task.path} try ${retryCount}`); + setBackupProgress(`Adding ${task.path} position ${task.position} try ${retryCount}`); var stream = fs.createReadStream(path.join(dataDir, task.path)); stream.on('error', function (error) { setBackupProgress(`read stream error for ${task.path}: ${error.message}`); diff --git a/src/syncer.js b/src/syncer.js index 81c3919b8..d9c337db6 100644 --- a/src/syncer.js +++ b/src/syncer.js @@ -104,14 +104,14 @@ function sync(dir, taskProcessor, concurrency, callback) { if (entryStat.isDirectory()) { traverse(entryPath); } else { - addQueue.push({ operation: 'add', path: entryPath, reason: 'new' }); + addQueue.push({ operation: 'add', path: entryPath, reason: 'new', position: addQueue.length }); } } else if (ISDIR(cacheStat.mode) && entryStat.isDirectory()) { // dir names match ++curCacheIndex; traverse(entryPath); } else if (ISFILE(cacheStat.mode) && entryStat.isFile()) { // file names match if (entryStat.mtime.getTime() !== cacheStat.mtime || entryStat.size != cacheStat.size || entryStat.inode !== cacheStat.inode) { // file changed - addQueue.push({ operation: 'add', path: entryPath, reason: 'changed' }); + addQueue.push({ operation: 'add', path: entryPath, reason: 'changed', position: addQueue.length }); } ++curCacheIndex; } else if (entryStat.isDirectory()) { // was a file, now a directory @@ -121,7 +121,7 @@ function sync(dir, taskProcessor, concurrency, callback) { } else { // was a dir, now a file delQueue.push({ operation: 'removedir', path: cachePath, reason: 'wasdir' }); while (curCacheIndex !== cache.length && cache[curCacheIndex].path.startsWith(cachePath)) ++curCacheIndex; - addQueue.push({ operation: 'add', path: entryPath, reason: 'wasdir' }); + addQueue.push({ operation: 'add', path: entryPath, reason: 'wasdir', position: addQueue.length }); } } } diff --git a/src/test/syncer-test.js b/src/test/syncer-test.js index 595441cc8..9cc3ad861 100644 --- a/src/test/syncer-test.js +++ b/src/test/syncer-test.js @@ -53,9 +53,9 @@ describe('Syncer', function () { expect(error).to.not.be.ok(); expect(gTasks).to.eql([ - { operation: 'add', path: 'src/index.js', reason: 'new' }, - { operation: 'add', path: 'test/test.js', reason: 'new' }, - { operation: 'add', path: 'walrus', reason: 'new' } + { operation: 'add', path: 'src/index.js', reason: 'new', position: 0 }, + { operation: 'add', path: 'test/test.js', reason: 'new', position: 1 }, + { operation: 'add', path: 'walrus', reason: 'new', position: 2 } ]); done(); }); @@ -70,7 +70,7 @@ describe('Syncer', function () { expect(error).to.not.be.ok(); expect(gTasks).to.eql([ - { operation: 'add', path: 'a/b/c/d/e', reason: 'new' } + { operation: 'add', path: 'a/b/c/d/e', reason: 'new', position: 0 } ]); done(); }); @@ -85,7 +85,7 @@ describe('Syncer', function () { expect(error).to.not.be.ok(); expect(gTasks).to.eql([ - { operation: 'add', path: 'readme', reason: 'new' } + { operation: 'add', path: 'readme', reason: 'new', position: 0 } ]); done(); }); @@ -107,8 +107,8 @@ describe('Syncer', function () { expect(error).to.not.be.ok(); expect(gTasks).to.eql([ - { operation: 'add', path: 'src/index.js', reason: 'changed' }, - { operation: 'add', path: 'test/test.js', reason: 'changed' } + { operation: 'add', path: 'src/index.js', reason: 'changed', position: 0 }, + { operation: 'add', path: 'test/test.js', reason: 'changed', position: 1 } ]); done(); @@ -209,7 +209,7 @@ describe('Syncer', function () { expect(gTasks).to.eql([ { operation: 'removedir', path: 'a/b', reason: 'missing' }, - { operation: 'add', path: 'a/f', reason: 'new' } + { operation: 'add', path: 'a/f', reason: 'new', position: 0 } ]); done(); @@ -234,7 +234,7 @@ describe('Syncer', function () { expect(gTasks).to.eql([ { operation: 'remove', path: 'data/test/test.js', reason: 'wasfile' }, - { operation: 'add', path: 'data/test/test.js/trick', reason: 'new' } + { operation: 'add', path: 'data/test/test.js/trick', reason: 'new', position: 0 } ]); done(); @@ -259,7 +259,7 @@ describe('Syncer', function () { expect(gTasks).to.eql([ { operation: 'removedir', path: 'test', reason: 'wasdir' }, - { operation: 'add', path: 'test', reason: 'wasdir' } + { operation: 'add', path: 'test', reason: 'wasdir', position: 0 } ]); done(); @@ -312,9 +312,9 @@ describe('Syncer', function () { { operation: 'removedir', path: 'j/l', reason: 'missing' }, { operation: 'removedir', path: 'j/m', reason: 'missing' }, - { operation: 'add', path: 'a/file', reason: 'new' }, - { operation: 'add', path: 'b', reason: 'changed' }, - { operation: 'add', path: 'j/k/file', reason: 'new' }, + { operation: 'add', path: 'a/file', reason: 'new', position: 0 }, + { operation: 'add', path: 'b', reason: 'changed', position: 1 }, + { operation: 'add', path: 'j/k/file', reason: 'new', position: 2 }, ]); gTasks = [ ];