From 91b2fb99f172e9d65c7cf758998b5bcdc391aefe Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 26 Jun 2008 04:14:02 +0000 Subject: [PATCH] Fix a few potential attachment errors --- chrome/content/zotero/xpcom/data/item.js | 2 ++ chrome/content/zotero/xpcom/schema.js | 26 +++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index 524eac0fb..084bccd35 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -2166,6 +2166,7 @@ Zotero.Item.prototype.getFile = function(row, skipExistsCheck) { } catch (e) { Zotero.debug('Invalid persistent descriptor'); + return false; } } } @@ -2191,6 +2192,7 @@ Zotero.Item.prototype.getFile = function(row, skipExistsCheck) { } catch (e) { Zotero.debug('Invalid relative descriptor'); + return false; } } } diff --git a/chrome/content/zotero/xpcom/schema.js b/chrome/content/zotero/xpcom/schema.js index c3ed65353..fbc8b2410 100644 --- a/chrome/content/zotero/xpcom/schema.js +++ b/chrome/content/zotero/xpcom/schema.js @@ -1569,6 +1569,22 @@ Zotero.Schema = new function(){ continue; } if (keys[id]) { + var renameTarget = storage37.clone(); + renameTarget.append(keys[id]); + if (renameTarget.exists()) { + if (!orphaned.exists()) { + orphaned.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0755); + } + var target = orphaned.clone(); + target.append(keys[id]); + var newName = null; + if (target.exists()) { + target.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0644); + newName = target.leafName; + target.remove(null); + } + renameTarget.moveTo(orphaned, newName); + } file.moveTo(null, keys[id]); moveReport += keys[id] + ' ' + id + "\n"; } @@ -1576,7 +1592,15 @@ Zotero.Schema = new function(){ if (!orphaned.exists()) { orphaned.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0755); } - file.moveTo(orphaned, null); + var target = orphaned.clone(); + target.append(file.leafName); + var newName = null; + if (target.exists()) { + target.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0644); + newName = target.leafName; + target.remove(null); + } + file.moveTo(orphaned, newName); } movedFiles37[id] = file; }