From 62930f65b4910681d876285a03ebe98e263f86bb Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 18 Nov 2020 12:41:47 +0530 Subject: [PATCH 1/5] fix the iOS Firefox fix --- www/common/cryptpad-common.js | 1 - 1 file changed, 1 deletion(-) diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 9a9807e7e..9f88e85a9 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -2079,7 +2079,6 @@ define([ var pre = document.createElement('pre'); pre.innerText = 'x'; - pre.style.display = 'none'; logger.appendChild(pre); } catch (err) { console.error(err); } }()); From e1850088461490437b46d100d7d4baa035d632b8 Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 18 Nov 2020 18:26:10 +0530 Subject: [PATCH 2/5] complete uploads in child processes also fix a nasty race condition for unowned file uploads --- lib/commands/upload.js | 22 ++++------------------ lib/storage/blob.js | 39 +++++++++++++++++++-------------------- lib/workers/db-worker.js | 33 +++++++++++++++++++++++++++++++++ lib/workers/index.js | 9 +++++++++ 4 files changed, 65 insertions(+), 38 deletions(-) diff --git a/lib/commands/upload.js b/lib/commands/upload.js index 7286caa93..6dc0aa911 100644 --- a/lib/commands/upload.js +++ b/lib/commands/upload.js @@ -75,21 +75,9 @@ Upload.upload = function (Env, safeKey, chunk, cb) { Env.blobStore.upload(safeKey, chunk, cb); }; -var reportStatus = function (Env, label, safeKey, err, id) { - var data = { - safeKey: safeKey, - err: err && err.message || err, - id: id, - }; - var method = err? 'error': 'info'; - Env.Log[method](label, data); -}; - Upload.complete = function (Env, safeKey, arg, cb) { - Env.blobStore.complete(safeKey, arg, function (err, id) { - reportStatus(Env, 'UPLOAD_COMPLETE', safeKey, err, id); - cb(err, id); - }); + Env.blobStore.closeBlobstage(safeKey); + Env.completeUpload(safeKey, arg, false, cb); }; Upload.cancel = function (Env, safeKey, arg, cb) { @@ -97,9 +85,7 @@ Upload.cancel = function (Env, safeKey, arg, cb) { }; Upload.complete_owned = function (Env, safeKey, arg, cb) { - Env.blobStore.completeOwned(safeKey, arg, function (err, id) { - reportStatus(Env, 'UPLOAD_COMPLETE_OWNED', safeKey, err, id); - cb(err, id); - }); + Env.blobStore.closeBlobstage(safeKey); + Env.completeUpload(safeKey, arg, true, cb); }; diff --git a/lib/storage/blob.js b/lib/storage/blob.js index dfbc802b4..044eeaeaa 100644 --- a/lib/storage/blob.js +++ b/lib/storage/blob.js @@ -139,6 +139,15 @@ var upload = function (Env, safeKey, content, cb) { } }; +var closeBlobstage = function (Env, safeKey) { + var session = Env.getSession(safeKey); + if (!(session && session.blobstage && typeof(session.blobstage.close) === 'function')) { + return; + } + session.blobstage.close(); + delete session.blobstage; +}; + // upload_cancel var upload_cancel = function (Env, safeKey, fileSize, cb) { var session = Env.getSession(safeKey); @@ -159,27 +168,22 @@ var upload_cancel = function (Env, safeKey, fileSize, cb) { // upload_complete var upload_complete = function (Env, safeKey, id, cb) { - var session = Env.getSession(safeKey); - - if (session.blobstage && session.blobstage.close) { - session.blobstage.close(); - delete session.blobstage; - } + closeBlobstage(Env, safeKey); var oldPath = makeStagePath(Env, safeKey); var newPath = makeBlobPath(Env, id); nThen(function (w) { // make sure the path to your final location exists - Fse.mkdirp(Path.dirname(newPath), function (e) { + Fse.mkdirp(Path.dirname(newPath), w(function (e) { if (e) { w.abort(); return void cb('RENAME_ERR'); } - }); + })); }).nThen(function (w) { // make sure there's not already something in that exact location - isFile(newPath, function (e, yes) { + isFile(newPath, w(function (e, yes) { if (e) { w.abort(); return void cb(e); @@ -188,8 +192,8 @@ var upload_complete = function (Env, safeKey, id, cb) { w.abort(); return void cb('RENAME_ERR'); } - cb(void 0, newPath, id); - }); + cb(void 0, id); + })); }).nThen(function () { // finally, move the old file to the new path // FIXME we could just move and handle the EEXISTS instead of the above block @@ -217,15 +221,7 @@ var tryId = function (path, cb) { // owned_upload_complete var owned_upload_complete = function (Env, safeKey, id, cb) { - var session = Env.getSession(safeKey); - - // the file has already been uploaded to the staging area - // close the pending writestream - if (session.blobstage && session.blobstage.close) { - session.blobstage.close(); - delete session.blobstage; - } - + closeBlobstage(Env, safeKey); if (!isValidId(id)) { return void cb('EINVAL_ID'); } @@ -582,6 +578,9 @@ BlobStore.create = function (config, _cb) { }, }, + closeBlobstage: function (safeKey) { + closeBlobstage(Env, safeKey); + }, complete: function (safeKey, id, _cb) { var cb = Util.once(Util.mkAsync(_cb)); if (!isValidSafeKey(safeKey)) { return void cb('INVALID_SAFEKEY'); } diff --git a/lib/workers/db-worker.js b/lib/workers/db-worker.js index 0b4c4d03d..9d5abf386 100644 --- a/lib/workers/db-worker.js +++ b/lib/workers/db-worker.js @@ -457,6 +457,38 @@ const evictInactive = function (data, cb) { Eviction(Env, cb); }; +var reportStatus = function (Env, label, safeKey, err, id) { + var data = { + safeKey: safeKey, + err: err && err.message || err, + id: id, + }; + var method = err? 'error': 'info'; + Env.Log[method](label, data); +}; + +const completeUpload = function (data, cb) { + if (!data) { return void cb('INVALID_ARGS'); } + var owned = data.owned; + var safeKey = data.safeKey; + var arg = data.arg; + + var method; + var label; + if (owned) { + method = 'completeOwned'; + label = 'UPLOAD_COMPLETE_OWNED'; + } else { + method = 'complete'; + label = 'UPLOAD_COMPLETE'; + } + + Env.blobStore[method](safeKey, arg, function (err, id) { + reportStatus(Env, label, safeKey, err, id); + cb(err, id); + }); +}; + const COMMANDS = { COMPUTE_INDEX: computeIndex, COMPUTE_METADATA: computeMetadata, @@ -471,6 +503,7 @@ const COMMANDS = { RUN_TASKS: runTasks, WRITE_TASK: writeTask, EVICT_INACTIVE: evictInactive, + COMPLETE_UPLOAD: completeUpload, }; COMMANDS.INLINE = function (data, cb) { diff --git a/lib/workers/index.js b/lib/workers/index.js index 522339812..b5704c68b 100644 --- a/lib/workers/index.js +++ b/lib/workers/index.js @@ -424,6 +424,15 @@ Workers.initialize = function (Env, config, _cb) { }, cb); }; + Env.completeUpload = function (safeKey, arg, owned, cb) { + sendCommand({ + command: "COMPLETE_UPLOAD", + owned: owned, + safeKey: safeKey, + arg: arg, + }, cb); + }; + cb(void 0); }); }; From faa84bcbd71a645c0e90b8cd36268edc61f850d3 Mon Sep 17 00:00:00 2001 From: ansuz Date: Thu, 19 Nov 2020 12:16:02 +0530 Subject: [PATCH 3/5] describe arguments for 'completeUpload' RPC --- lib/workers/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/workers/index.js b/lib/workers/index.js index b5704c68b..fe868e250 100644 --- a/lib/workers/index.js +++ b/lib/workers/index.js @@ -427,9 +427,9 @@ Workers.initialize = function (Env, config, _cb) { Env.completeUpload = function (safeKey, arg, owned, cb) { sendCommand({ command: "COMPLETE_UPLOAD", - owned: owned, - safeKey: safeKey, - arg: arg, + owned: owned, // Boolean + safeKey: safeKey, // String (public key) + arg: arg, // String (file id) }, cb); }; From 9bbc3acf3ab688617d9ac3f17fd4a146835e19ae Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 18 Nov 2020 15:11:34 +0100 Subject: [PATCH 4/5] Don't show XDR encoding errors --- customize.dist/loading.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/customize.dist/loading.js b/customize.dist/loading.js index edb66ef0a..b0d66981c 100644 --- a/customize.dist/loading.js +++ b/customize.dist/loading.js @@ -329,6 +329,12 @@ button.primary:hover{ window.CryptPad_loadingError = function (err) { if (!built) { return; } + + if (err === 'Error: XDR encoding failure') { + console.warn(err); + return; + } + hasErrored = true; var err2; if (err === 'Script error.') { From 1aa790e02d7b730bb62c20318947054744973158 Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 18 Nov 2020 15:11:34 +0100 Subject: [PATCH 5/5] Don't show XDR encoding errors --- customize.dist/loading.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/customize.dist/loading.js b/customize.dist/loading.js index edb66ef0a..b0d66981c 100644 --- a/customize.dist/loading.js +++ b/customize.dist/loading.js @@ -329,6 +329,12 @@ button.primary:hover{ window.CryptPad_loadingError = function (err) { if (!built) { return; } + + if (err === 'Error: XDR encoding failure') { + console.warn(err); + return; + } + hasErrored = true; var err2; if (err === 'Script error.') {