Fix error closing ZIP reader during file sync on Windows

In Z7 on Windows 10 (but not 11 for me), nsIZipReader doesn't properly
close the file after `findEntries()` is called (as discovered by
@abaevbog), so a `remove()` on the downloaded ZIP file during file
syncing triggers an access-denied error. Setting the zip-reader variable
to null and forcing garbage collection seems to fix it. Doing this
everywhere we use nsIZipReader just to be safe.

I found the `forceGC()` in only one test file in fx102, but setting the
reader to null is done more widely, so maybe they just don't try to
delete ZIP files before GC happens and manage to avoid this bug.

Fixes #3369
This commit is contained in:
Dan Stillman 2023-08-31 06:04:46 -04:00
parent 794e89d307
commit b918ad2892
3 changed files with 18 additions and 0 deletions

View file

@ -56,6 +56,8 @@ class EPUB {
close() {
this._zipReader.close();
this._zipReader = null
Cu.forceGC();
}
async* getSectionDocuments() {

View file

@ -136,6 +136,8 @@ Zotero.Dictionaries = new function () {
}
zipReader.close();
zipReader = null
Cu.forceGC();
await OS.File.remove(xpiPath);
await _loadDirectory(dir);
}

View file

@ -794,6 +794,8 @@ Zotero.Sync.Storage.Local = {
catch (e) {
Zotero.debug(zipFile.leafName + " is not a valid ZIP file", 2);
zipReader.close();
zipReader = null
Cu.forceGC();
try {
zipFile.remove(false);
@ -813,6 +815,8 @@ Zotero.Sync.Storage.Local = {
}
catch (e) {
zipReader.close();
zipReader = null
Cu.forceGC();
throw e;
}
@ -900,6 +904,8 @@ Zotero.Sync.Storage.Local = {
Zotero.logError(e);
zipReader.close();
zipReader = null
Cu.forceGC();
Zotero.File.checkFileAccessError(e, destPath, 'create');
}
@ -914,6 +920,9 @@ Zotero.Sync.Storage.Local = {
}
catch (e) {}
zipReader.close();
zipReader = null
Cu.forceGC();
// TODO: localize
var msg = "Due to a Windows path length limitation, your Zotero data directory "
+ "is too deep in the filesystem for syncing to work reliably. "
@ -950,6 +959,8 @@ Zotero.Sync.Storage.Local = {
}
zipReader.close();
zipReader = null
Cu.forceGC();
Zotero.File.checkFileAccessError(e, destPath, 'create');
}
@ -962,6 +973,9 @@ Zotero.Sync.Storage.Local = {
}
}
zipReader.close();
zipReader = null
Cu.forceGC();
zipFile.remove(false);
return returnFile;