From d95a3ac92ef9039df7ac1cb09b67d5fed87e61d9 Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 16 Dec 2016 11:27:59 +0100 Subject: [PATCH] Fix an issue when deleting a key from the proxy --- customize.dist/fsStore.js | 2 +- www/file/fileObject.js | 10 ++++++++-- www/file/inner.html | 1 + www/file/main.js | 24 +++++++++++++++--------- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/customize.dist/fsStore.js b/customize.dist/fsStore.js index 215c515ab..f4bc6c21c 100644 --- a/customize.dist/fsStore.js +++ b/customize.dist/fsStore.js @@ -143,7 +143,7 @@ define([ }); }).on('ready', function () { - if (JSON.stringify(rt.proxy) === '{}') { + if (!rt.proxy[Cryptpad.storageKey] || !Cryptpad.isArray(rt.proxy[Cryptpad.storageKey])) { var oldStore = Cryptpad.getStore(true); oldStore.get(Cryptpad.storageKey, function (err, s) { rt.proxy.filesData = s; diff --git a/www/file/fileObject.js b/www/file/fileObject.js index 174c8bd46..a254ef635 100644 --- a/www/file/fileObject.js +++ b/www/file/fileObject.js @@ -213,6 +213,7 @@ define([ for (var e in root) { if (isFile(root[e])) { if (compareFiles(href, root[e])) { + root[e] = undefined; delete root[e]; } } else { @@ -256,6 +257,7 @@ define([ } else if (path[0] === UNSORTED) { parentEl.splice(key, 1); } else { + parentEl[key] = undefined; delete parentEl[key]; } checkDeletedFiles(); @@ -387,7 +389,6 @@ define([ log("A file with the same name already exist at the new location. Rename the file and try again."); return; } - newParent[newName] = element; if (!keepOld) { deleteFromObject(elementPath); } if(cb) { cb(); } @@ -454,8 +455,9 @@ define([ if (index > -1) { array.splice(index, 1); } - // Remove the array is empty to have a cleaner object in chainpad + // Remove the array if empty to have a cleaner object in chainpad if (array.length === 0) { + files[TRASH][name] = undefined; delete files[TRASH][name]; } }; @@ -512,6 +514,7 @@ define([ logError("Unable to locate the element to remove from trash: ", path); return; } + parentEl[name] = undefined; delete parentEl[name]; } checkDeletedFiles(); @@ -543,6 +546,7 @@ define([ return; } parentEl[newName] = element; + parentEl[oldName] = undefined; delete parentEl[oldName]; cb(); }; @@ -612,6 +616,7 @@ define([ for (var el in element) { if (!isFile(element[el]) && !isFolder(element[el])) { debug("An element in ROOT was not a folder nor a file. ", element[el]); + element[el] = undefined; delete element[el]; } else if (isFolder(element[el])) { fixRoot(element[el]); @@ -630,6 +635,7 @@ define([ for (var el in tr) { if (!$.isArray(tr[el])) { debug("An element in TRASH root is not an array. ", tr[el]); + tr[el] = undefined; delete tr[el]; } else { toClean = []; diff --git a/www/file/inner.html b/www/file/inner.html index dc9b5bd44..46991aa9f 100644 --- a/www/file/inner.html +++ b/www/file/inner.html @@ -4,6 +4,7 @@ + diff --git a/www/file/main.js b/www/file/main.js index efe6a71e8..d2ce65a95 100644 --- a/www/file/main.js +++ b/www/file/main.js @@ -8,8 +8,6 @@ define([ 'json.sortify', '/common/cryptpad-common.js', '/file/fileObject.js', - '/bower_components/jquery/dist/jquery.min.js', - '/bower_components/bootstrap/dist/js/bootstrap.min.js', '/customize/pad.js' ], function (Config, Listmap, Crypto, TextPatcher, Messages, JSONSortify, Cryptpad, FO) { var module = window.MODULE = {}; @@ -1316,25 +1314,33 @@ define([ } }); - files.on('change', [], function () { + var onRefresh = { + refresh: function() { + if (onRefresh.to) { + window.clearTimeout(onRefresh.to); + } + onRefresh.to = window.setTimeout(refresh, 500); + } + }; + files.on('change', [], function (o, n, p) { var path = arguments[2]; if ((filesOp.isPathInUnsorted(currentPath) && filesOp.isPathInUnsorted(path)) || (path.length >= currentPath.length && filesOp.isSubpath(path, currentPath)) || (filesOp.isPathInTrash(currentPath) && filesOp.isPathInTrash(path))) { - // Reload after 50ms to make sure all the change events have been received - window.setTimeout(refresh, 200); + // Reload after a few ms to make sure all the change events have been received + onRefresh.refresh(); } else if (path.length && path[0] === FILES_DATA) { refreshFilesData(); } module.resetTree(); return false; - }).on('remove', [], function () { + }).on('remove', [], function (o, p) { var path = arguments[1]; if ((filesOp.isPathInUnsorted(currentPath) && filesOp.isPathInUnsorted(path)) || (path.length >= currentPath.length && filesOp.isSubpath(path, currentPath)) || (filesOp.isPathInTrash(currentPath) && filesOp.isPathInTrash(path))) { - // Reload after 50ms to make sure all the change events have been received - window.setTimeout(refresh, 200); + // Reload after a few to make sure all the change events have been received + onRefresh.to = window.setTimeout(refresh, 500); } module.resetTree(); return false; @@ -1373,7 +1379,7 @@ define([ readOnly: false, validateKey: secret.keys.validateKey || undefined, crypto: Crypto.createEncryptor(secret.keys), - //logging: true + logging: false }; var rt = window.rt = module.rt = Listmap.create(listmapConfig);