From d1e1a11e387427b55b15c2ab0f77be70fa69cbbb Mon Sep 17 00:00:00 2001 From: ansuz Date: Fri, 20 Sep 2019 13:37:38 +0200 Subject: [PATCH] fix path issues in blobStore --- storage/blob.js | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/storage/blob.js b/storage/blob.js index aa0f43528..317d7755f 100644 --- a/storage/blob.js +++ b/storage/blob.js @@ -17,34 +17,19 @@ var isValidId = function (id) { // helpers -// /blob/// -var makePathToBlob = function (Env, blobId) { - return Path.join(Env.blobPath, blobId.slice(0, 2)); -}; - // /blob//// var makeBlobPath = function (Env, blobId) { - return Path.join(makePathToBlob(Env, blobId), blobId); -}; - -// /blobstate/ -var makePathToStage = function (Env, safeKey) { - return Path.join(Env.blobStagingPath, safeKey.slice(0, 2)); + return Path.join(Env.blobPath, blobId.slice(0, 2), blobId); }; // /blobstate// var makeStagePath = function (Env, safeKey) { - return Path.join(makePathToStage(Env, safeKey), safeKey); -}; - -// /blob/// -var makePathToProof = function (Env, safeKey, blobId) { - return Path.join(Env.blobPath, safeKey.slice(0, 3), safeKey, blobId.slice(0, 2), blobId); + return Path.join(Env.blobStagingPath, safeKey.slice(0, 2), safeKey); }; // /blob//// var makeProofPath = function (Env, safeKey, blobId) { - return Path.join(makePathToProof(Env, safeKey, blobId), blobId); + return Path.join(Env.blobPath, safeKey.slice(0, 3), safeKey, blobId.slice(0, 2), blobId); }; // getUploadSize: used by @@ -125,8 +110,10 @@ var upload = function (Env, safeKey, content, cb) { return cb('E_OVER_LIMIT'); } + var stagePath = makeStagePath(Env, safeKey); + if (!session.blobstage) { - makeFileStream(makePathToStage(Env, safeKey), makeStagePath(Env, safeKey), function (e, stream) { + makeFileStream(Path.dirname(stagePath), stagePath, function (e, stream) { if (!stream) { return void cb(e); } var blobstage = session.blobstage = stream; @@ -170,7 +157,7 @@ var upload_complete = function (Env, safeKey, id, cb) { nThen(function (w) { // make sure the path to your final location exists - Fse.mkdirp(makePathToBlob(Env, id), function (e) { + Fse.mkdirp(Path.dirname(newPath), function (e) { if (e) { w.abort(); return void cb('RENAME_ERR'); @@ -237,10 +224,8 @@ var owned_upload_complete = function (Env, safeKey, id, cb) { return void cb('EINVAL_CONFIG'); } - var ownPath = makePathToProof(Env, safeKey, id); - var filePath = makePathToBlob(Env, id); - var finalPath = makeBlobPath(Env, id); + var finalOwnPath = makeProofPath(Env, safeKey, id); // the user wants to move it into blob and create a empty file with the same id @@ -249,13 +234,13 @@ var owned_upload_complete = function (Env, safeKey, id, cb) { nThen(function (w) { // make the requisite directory structure using Mkdirp - Fse.mkdirp(filePath, w(function (e /*, path */) { + Fse.mkdirp(Path.dirname(finalPath), w(function (e /*, path */) { if (e) { // does not throw error if the directory already existed w.abort(); return void cb(e.code); } })); - Fse.mkdirp(ownPath, w(function (e /*, path */) { + Fse.mkdirp(Path.dirname(finalOwnPath), w(function (e /*, path */) { if (e) { // does not throw error if the directory already existed w.abort(); return void cb(e.code);