|
|
@ -37,6 +37,14 @@ var makeProofPath = function (Env, safeKey, blobId) {
|
|
|
|
return Path.join(Env.blobPath, safeKey.slice(0, 3), safeKey, blobId.slice(0, 2), blobId);
|
|
|
|
return Path.join(Env.blobPath, safeKey.slice(0, 3), safeKey, blobId.slice(0, 2), blobId);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var parseProofPath = function (path) {
|
|
|
|
|
|
|
|
var parts = path.split('/');
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
blobId: parts[parts.length -1],
|
|
|
|
|
|
|
|
safeKey: parts[parts.length - 3],
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// getUploadSize: used by
|
|
|
|
// getUploadSize: used by
|
|
|
|
// getFileSize
|
|
|
|
// getFileSize
|
|
|
|
var getUploadSize = function (Env, blobId, cb) {
|
|
|
|
var getUploadSize = function (Env, blobId, cb) {
|
|
|
@ -346,11 +354,11 @@ var restoreProof = function (Env, safeKey, blobId, cb) {
|
|
|
|
Fse.move(archivePath, proofPath, cb);
|
|
|
|
Fse.move(archivePath, proofPath, cb);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var makeWalker = function (n, handleChild, cb) {
|
|
|
|
var makeWalker = function (n, handleChild, done) {
|
|
|
|
if (!n || typeof(n) !== 'number' || n < 2) { n = 2; }
|
|
|
|
if (!n || typeof(n) !== 'number' || n < 2) { n = 2; }
|
|
|
|
|
|
|
|
|
|
|
|
var W;
|
|
|
|
var W;
|
|
|
|
var nt = nThen(function (w) {
|
|
|
|
nThen(function (w) {
|
|
|
|
// this asynchronous bit defers the completion of this block until
|
|
|
|
// this asynchronous bit defers the completion of this block until
|
|
|
|
// synchronous execution has completed. This means you must create
|
|
|
|
// synchronous execution has completed. This means you must create
|
|
|
|
// the walker and start using it synchronously or else it will call back
|
|
|
|
// the walker and start using it synchronously or else it will call back
|
|
|
@ -358,7 +366,7 @@ var makeWalker = function (n, handleChild, cb) {
|
|
|
|
setTimeout(w());
|
|
|
|
setTimeout(w());
|
|
|
|
W = w;
|
|
|
|
W = w;
|
|
|
|
}).nThen(function () {
|
|
|
|
}).nThen(function () {
|
|
|
|
cb();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// do no more than 20 jobs at a time
|
|
|
|
// do no more than 20 jobs at a time
|
|
|
@ -366,21 +374,28 @@ var makeWalker = function (n, handleChild, cb) {
|
|
|
|
|
|
|
|
|
|
|
|
var recurse = function (path) {
|
|
|
|
var recurse = function (path) {
|
|
|
|
tasks.take(function (give) {
|
|
|
|
tasks.take(function (give) {
|
|
|
|
var done = give(W());
|
|
|
|
var next = give(W());
|
|
|
|
Fs.readdir(path, function (err, dir) {
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
nThen(function (w) {
|
|
|
|
if (err.code === 'ENOTDIR') {
|
|
|
|
// check if the path is a directory...
|
|
|
|
return void handleChild(path, done);
|
|
|
|
Fs.stat(path, w(function (err, stats) {
|
|
|
|
|
|
|
|
if (err) { return next(); }
|
|
|
|
|
|
|
|
if (!stats.isDirectory()) {
|
|
|
|
|
|
|
|
w.abort();
|
|
|
|
|
|
|
|
return void handleChild(void 0, path, next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// XXX handle other error
|
|
|
|
// fall through
|
|
|
|
return done();
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}).nThen(function () {
|
|
|
|
// everything is fine and it's a directory...
|
|
|
|
// handle directories
|
|
|
|
if (dir.length === 0) { return done(); }
|
|
|
|
Fs.readdir(path, function (err, dir) {
|
|
|
|
dir.forEach(function (d) {
|
|
|
|
if (err) { return next(); }
|
|
|
|
recurse(Path.join(path, d));
|
|
|
|
// everything is fine and it's a directory...
|
|
|
|
|
|
|
|
dir.forEach(function (d) {
|
|
|
|
|
|
|
|
recurse(Path.join(path, d));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
done();
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -392,17 +407,28 @@ var listProofs = function (root, handler, cb) {
|
|
|
|
Fs.readdir(root, function (err, dir) {
|
|
|
|
Fs.readdir(root, function (err, dir) {
|
|
|
|
if (err) { return void cb(err); }
|
|
|
|
if (err) { return void cb(err); }
|
|
|
|
|
|
|
|
|
|
|
|
var walk = makeWalker(20, function (path, next) {
|
|
|
|
var walk = makeWalker(20, function (err, path, next) {
|
|
|
|
// path is the path to a child node on the filesystem
|
|
|
|
// path is the path to a child node on the filesystem
|
|
|
|
|
|
|
|
|
|
|
|
// next handles the next job in a queue
|
|
|
|
// next handles the next job in a queue
|
|
|
|
|
|
|
|
|
|
|
|
// iterate over proofs
|
|
|
|
// iterate over proofs
|
|
|
|
// check for presence of corresponding files
|
|
|
|
// check for presence of corresponding files
|
|
|
|
|
|
|
|
Fs.stat(path, function (err, stats) {
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
|
|
|
|
return void handler(err, void 0, next);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
handler(path, next);
|
|
|
|
var parsed = parseProofPath(path);
|
|
|
|
//console.log(path);
|
|
|
|
handler(void 0, {
|
|
|
|
//next();
|
|
|
|
path: path,
|
|
|
|
|
|
|
|
blobId: parsed.blobId,
|
|
|
|
|
|
|
|
safeKey: parsed.safeKey,
|
|
|
|
|
|
|
|
atime: stats.atime,
|
|
|
|
|
|
|
|
ctime: stats.ctime,
|
|
|
|
|
|
|
|
mtime: stats.mtime,
|
|
|
|
|
|
|
|
}, next);
|
|
|
|
|
|
|
|
});
|
|
|
|
}, function () {
|
|
|
|
}, function () {
|
|
|
|
// called when there are no more directories or children to process
|
|
|
|
// called when there are no more directories or children to process
|
|
|
|
cb();
|
|
|
|
cb();
|
|
|
@ -420,8 +446,19 @@ var listBlobs = function (root, handler, cb) {
|
|
|
|
// iterate over files
|
|
|
|
// iterate over files
|
|
|
|
Fs.readdir(root, function (err, dir) {
|
|
|
|
Fs.readdir(root, function (err, dir) {
|
|
|
|
if (err) { return void cb(err); }
|
|
|
|
if (err) { return void cb(err); }
|
|
|
|
var walk = makeWalker(20, function (path, next) {
|
|
|
|
var walk = makeWalker(20, function (err, path, next) {
|
|
|
|
handler(path, next);
|
|
|
|
Fs.stat(path, function (err, stats) {
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
|
|
|
|
return void handler(err, void 0, next);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
handler(void 0, {
|
|
|
|
|
|
|
|
blobId: Path.basename(path),
|
|
|
|
|
|
|
|
atime: stats.atime,
|
|
|
|
|
|
|
|
ctime: stats.ctime,
|
|
|
|
|
|
|
|
mtime: stats.mtime,
|
|
|
|
|
|
|
|
}, next);
|
|
|
|
|
|
|
|
});
|
|
|
|
}, function () {
|
|
|
|
}, function () {
|
|
|
|
cb();
|
|
|
|
cb();
|
|
|
|
});
|
|
|
|
});
|
|
|
|