Use OS.File.move() for data-dir migration on Windows, and make automatic

Previously on Windows, where we don't have /bin/mv, we were recursing
into the data directory and copying files individually, which is very
slow, so automatic migration was disabled. Instead, try moving
directories with OS.File.move() with the `noCopy` flag. Moving
directories is technically unsupported by OS.File, but probably only
because of the possibility of a cross-volume copy (which is only
implemented for some platforms), and using `noCopy` hopefully prevents
that. If someone does have their data directory or storage directory on
a different volume, the migration might be quite slow, but leaving a
data directory behind in the Firefox profile directory (where it can be
easily misplaced with a seemingly unrelated Firefox reset) is worse.
This commit is contained in:
Dan Stillman 2017-02-22 04:56:49 -05:00
parent 1ff1fabb31
commit 0964277a37
3 changed files with 61 additions and 23 deletions

View file

@ -59,19 +59,33 @@ describe("Zotero.DataDirectory", function () {
stubs.pipeExists.restore();
});
// Force non-mv mode
var disableCommandMode = function () {
// Force non-mv mode
var origFunc = OS.File.exists;
if (!stubs.canMoveDirectoryAtomic) {
stubs.canMoveDirectoryAtomic = sinon.stub(Zotero.File, "canMoveDirectoryAtomic")
if (!stubs.canMoveDirectoryWithCommand) {
stubs.canMoveDirectoryWithCommand = sinon.stub(Zotero.File, "canMoveDirectoryWithCommand")
.returns(false);
}
};
// Force non-OS.File.move() mode
var disableFunctionMode = function () {
if (!stubs.canMoveDirectoryWithFunction) {
stubs.canMoveDirectoryWithFunction = sinon.stub(Zotero.File, "canMoveDirectoryWithFunction")
.returns(false);
}
};
var resetCommandMode = function () {
if (stubs.canMoveDirectoryAtomic) {
stubs.canMoveDirectoryAtomic.restore();
stubs.canMoveDirectoryAtomic = undefined;
if (stubs.canMoveDirectoryWithCommand) {
stubs.canMoveDirectoryWithCommand.restore();
stubs.canMoveDirectoryWithCommand = undefined;
}
};
var resetFunctionMode = function () {
if (stubs.canMoveDirectoryWithFunction) {
stubs.canMoveDirectoryWithFunction.restore();
stubs.canMoveDirectoryWithFunction = undefined;
}
};
@ -144,10 +158,12 @@ describe("Zotero.DataDirectory", function () {
beforeEach(function () {
disableCommandMode();
disableFunctionMode();
});
after(function () {
resetCommandMode();
resetFunctionMode();
});
var tests = [];
@ -157,11 +173,7 @@ describe("Zotero.DataDirectory", function () {
it("should skip automatic migration if target directory exists and is non-empty", function* () {
resetCommandMode();
// No automatic migration without atomic directory move
if (!Zotero.File.canMoveDirectoryAtomic()) {
this.skip();
}
resetFunctionMode();
yield populateDataDirectory(oldDir);
yield OS.File.remove(oldMigrationMarker);
@ -347,10 +359,12 @@ describe("Zotero.DataDirectory", function () {
before(function () {
disableCommandMode();
disableFunctionMode();
});
after(function () {
resetCommandMode();
resetFunctionMode();
});
it("should handle partial failure", function* () {