From 7bdabb5cbc3853090b3b133587e820e48495b75d Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 6 Jul 2021 15:42:37 +0530 Subject: [PATCH] archive blocks before overwriting them --- lib/storage/block.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/storage/block.js b/lib/storage/block.js index d3e7a1869..1078f6d2e 100644 --- a/lib/storage/block.js +++ b/lib/storage/block.js @@ -72,9 +72,16 @@ Block.write = function (Env, publicKey, buffer, _cb) { w.abort(); cb(err); })); + }).nThen(function (w) { + Block.archive(Env, publicKey, w(function (/* err */) { + /* + we proceed even if there are errors. + it might be ENOENT (there is no file to archive) + or EACCES (bad filesystem permissions for the existing archived block?) + or lots of other things, none of which justify preventing the write + */ + })); }).nThen(function () { - // XXX BLOCK check whether this overwrites a block - // XXX archive the old one if so Fs.writeFile(path, buffer, { encoding: 'binary' }, cb); }); };