From 4df35b829b88bfc94b79fddfb5a635ce33de8f6f Mon Sep 17 00:00:00 2001 From: tophf Date: Mon, 15 May 2017 12:40:35 +0300 Subject: [PATCH] import: don't blindly overwrite styles with same id --- backup/fileSaveLoad.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/backup/fileSaveLoad.js b/backup/fileSaveLoad.js index 23ab0de5..501c1aa0 100644 --- a/backup/fileSaveLoad.js +++ b/backup/fileSaveLoad.js @@ -102,7 +102,8 @@ function importFromString(jsonString) { item.name = item.name.trim(); const byId = BG.cachedStyles.byId.get(item.id); const byName = oldStylesByName.get(item.name); - const oldStyle = byId && byId.name.trim() == item.name || !byName ? byId : byName; + const oldStyle = byId && sameStyle(byId, item) ? byId : byName; + oldStylesByName.delete(item.name); if (oldStyle == byName && byName) { item.id = byName.id; } @@ -119,6 +120,12 @@ function importFromString(jsonString) { return {oldStyle, metaEqual, codeEqual}; } + function sameStyle(oldStyle, newStyle) { + return oldStyle.name.trim() === newStyle.name.trim() || + ['updateUrl', 'originalMd5', 'originalDigest'] + .some(field => oldStyle[field] && oldStyle[field] == newStyle[field]); + } + function account({style, info, resolve}) { renderQueue.push(style); if (performance.now() - lastRenderTime > RENDER_NAP_TIME_MAX