Fix snapshots of pages without extensions on Linux -- nsIMIMEService::getPrimaryExtension() doesn't work on Linux
Better error recovery in attachment methods
This commit is contained in:
parent
a16552cd72
commit
02f205e919
|
@ -77,6 +77,7 @@ Zotero.Attachments = new function(){
|
|||
// hmph
|
||||
Zotero.DB.rollbackTransaction();
|
||||
|
||||
try {
|
||||
// Clean up
|
||||
if (itemID){
|
||||
var itemDir = Zotero.getStorageDirectory();
|
||||
|
@ -85,6 +86,9 @@ Zotero.Attachments = new function(){
|
|||
itemDir.remove(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {}
|
||||
|
||||
throw (e);
|
||||
}
|
||||
return itemID;
|
||||
|
@ -145,6 +149,7 @@ Zotero.Attachments = new function(){
|
|||
catch (e){
|
||||
Zotero.DB.rollbackTransaction();
|
||||
|
||||
try {
|
||||
// Clean up
|
||||
if (itemID){
|
||||
var itemDir = Zotero.getStorageDirectory();
|
||||
|
@ -153,6 +158,9 @@ Zotero.Attachments = new function(){
|
|||
itemDir.remove(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {}
|
||||
|
||||
throw (e);
|
||||
}
|
||||
return itemID;
|
||||
|
@ -226,6 +234,19 @@ Zotero.Attachments = new function(){
|
|||
}
|
||||
catch (e){
|
||||
Zotero.DB.rollbackTransaction();
|
||||
|
||||
try {
|
||||
// Clean up
|
||||
if (itemID) {
|
||||
var destDir = Zotero.getStorageDirectory();
|
||||
destDir.append(itemID);
|
||||
if (destDir.exists()) {
|
||||
destDir.remove(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {}
|
||||
|
||||
throw (e);
|
||||
}
|
||||
}
|
||||
|
@ -305,6 +326,7 @@ Zotero.Attachments = new function(){
|
|||
|
||||
Zotero.DB.beginTransaction();
|
||||
|
||||
try {
|
||||
// Create a new attachment
|
||||
var attachmentItem = Zotero.Items.getNewItemByType(Zotero.ItemTypes.getID('attachment'));
|
||||
attachmentItem.setField('title', title);
|
||||
|
@ -337,6 +359,7 @@ Zotero.Attachments = new function(){
|
|||
file.append(fileName);
|
||||
|
||||
wbp.progressListener = new Zotero.WebProgressFinishListener(function(){
|
||||
try {
|
||||
_addToDB(file, url, title, Zotero.Attachments.LINK_MODE_IMPORTED_URL, mimeType,
|
||||
charsetID, sourceItemID, itemID);
|
||||
|
||||
|
@ -350,12 +373,34 @@ Zotero.Attachments = new function(){
|
|||
}
|
||||
|
||||
Zotero.DB.commitTransaction();
|
||||
}
|
||||
catch (e) {
|
||||
Zotero.DB.rollbackTransaction();
|
||||
}
|
||||
|
||||
Zotero.Fulltext.indexDocument(document, itemID);
|
||||
});
|
||||
|
||||
wbp.saveDocument(document, file, destDir, mimeType, encodingFlags, false);
|
||||
}
|
||||
catch (e) {
|
||||
Zotero.DB.rollbackTransaction();
|
||||
|
||||
try {
|
||||
// Clean up
|
||||
if (itemID) {
|
||||
var destDir = Zotero.getStorageDirectory();
|
||||
destDir.append(itemID);
|
||||
if (destDir.exists()) {
|
||||
destDir.remove(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {}
|
||||
|
||||
throw (e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function _getFileNameFromURL(url, mimeType){
|
||||
|
@ -368,10 +413,14 @@ Zotero.Attachments = new function(){
|
|||
}
|
||||
|
||||
if (mimeType){
|
||||
try {
|
||||
var ext = Components.classes["@mozilla.org/mime;1"]
|
||||
.getService(Components.interfaces.nsIMIMEService)
|
||||
.getPrimaryExtension(mimeType, nsIURL.fileExt ? nsIURL.fileExt : null);
|
||||
}
|
||||
// getPrimaryExtension doesn't work on Linux
|
||||
catch (e) {}
|
||||
}
|
||||
|
||||
return nsIURL.host + (ext ? '.' + ext : '');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user