Data directory migration
This adds a new button to the Advanced prefs to migrate the data directory to
$HOME/Zotero. The button only appears if the data directory is set to the
default location within a profile directory (including the other program from
the one running, even though that's technically stored as a custom data
directory).
On Mac/Linux, directories within the data directory are moved with /bin/mv. On
Windows, or if that fails, they're copied recursively using OS.File.move()
(which annoyingly doesn't reliably support directory moving). The former should
be instantaneous on most systems (unless the data directory or 'storage' were
on a different filesystem from $HOME).
If the database fails to transfer, migration fails and the data directory
setting remains on the old directory. If the database transfers but other files
fail, the data directory setting is updated. In both cases, the user is
encouraged to migrate remaining files manually with a button that reveals the
directories and quits the program.
This isn't yet tested on Linux or Windows, and migration isn't yet suggested
automatically.
Adds Zotero.File.reveal(), Zotero.File.directoryIsEmpty(), and
Zotero.File.moveDirectory().
2016-11-12 19:20:34 +00:00
|
|
|
"use strict";
|
|
|
|
|
2016-11-27 03:41:26 +00:00
|
|
|
describe("Zotero.DataDirectory", function () {
|
Data directory migration
This adds a new button to the Advanced prefs to migrate the data directory to
$HOME/Zotero. The button only appears if the data directory is set to the
default location within a profile directory (including the other program from
the one running, even though that's technically stored as a custom data
directory).
On Mac/Linux, directories within the data directory are moved with /bin/mv. On
Windows, or if that fails, they're copied recursively using OS.File.move()
(which annoyingly doesn't reliably support directory moving). The former should
be instantaneous on most systems (unless the data directory or 'storage' were
on a different filesystem from $HOME).
If the database fails to transfer, migration fails and the data directory
setting remains on the old directory. If the database transfers but other files
fail, the data directory setting is updated. In both cases, the user is
encouraged to migrate remaining files manually with a button that reveals the
directories and quits the program.
This isn't yet tested on Linux or Windows, and migration isn't yet suggested
automatically.
Adds Zotero.File.reveal(), Zotero.File.directoryIsEmpty(), and
Zotero.File.moveDirectory().
2016-11-12 19:20:34 +00:00
|
|
|
var tmpDir, oldDir, newDir, dbFilename, oldDBFile, newDBFile, oldStorageDir, newStorageDir,
|
|
|
|
oldTranslatorsDir, newTranslatorsDir, translatorName1, translatorName2,
|
|
|
|
oldStorageDir1, newStorageDir1, storageFile1, oldStorageDir2, newStorageDir2, storageFile2,
|
|
|
|
str1, str2, str3, str4, str5, str6,
|
|
|
|
oldMigrationMarker, newMigrationMarker,
|
2016-11-24 06:19:52 +00:00
|
|
|
stubs = {};
|
Data directory migration
This adds a new button to the Advanced prefs to migrate the data directory to
$HOME/Zotero. The button only appears if the data directory is set to the
default location within a profile directory (including the other program from
the one running, even though that's technically stored as a custom data
directory).
On Mac/Linux, directories within the data directory are moved with /bin/mv. On
Windows, or if that fails, they're copied recursively using OS.File.move()
(which annoyingly doesn't reliably support directory moving). The former should
be instantaneous on most systems (unless the data directory or 'storage' were
on a different filesystem from $HOME).
If the database fails to transfer, migration fails and the data directory
setting remains on the old directory. If the database transfers but other files
fail, the data directory setting is updated. In both cases, the user is
encouraged to migrate remaining files manually with a button that reveals the
directories and quits the program.
This isn't yet tested on Linux or Windows, and migration isn't yet suggested
automatically.
Adds Zotero.File.reveal(), Zotero.File.directoryIsEmpty(), and
Zotero.File.moveDirectory().
2016-11-12 19:20:34 +00:00
|
|
|
|
|
|
|
before(function* () {
|
|
|
|
tmpDir = yield getTempDirectory();
|
|
|
|
oldDir = OS.Path.join(tmpDir, "old");
|
|
|
|
newDir = OS.Path.join(tmpDir, "new");
|
2016-11-27 03:41:26 +00:00
|
|
|
dbFilename = Zotero.DataDirectory.getDatabaseFilename();
|
Data directory migration
This adds a new button to the Advanced prefs to migrate the data directory to
$HOME/Zotero. The button only appears if the data directory is set to the
default location within a profile directory (including the other program from
the one running, even though that's technically stored as a custom data
directory).
On Mac/Linux, directories within the data directory are moved with /bin/mv. On
Windows, or if that fails, they're copied recursively using OS.File.move()
(which annoyingly doesn't reliably support directory moving). The former should
be instantaneous on most systems (unless the data directory or 'storage' were
on a different filesystem from $HOME).
If the database fails to transfer, migration fails and the data directory
setting remains on the old directory. If the database transfers but other files
fail, the data directory setting is updated. In both cases, the user is
encouraged to migrate remaining files manually with a button that reveals the
directories and quits the program.
This isn't yet tested on Linux or Windows, and migration isn't yet suggested
automatically.
Adds Zotero.File.reveal(), Zotero.File.directoryIsEmpty(), and
Zotero.File.moveDirectory().
2016-11-12 19:20:34 +00:00
|
|
|
oldDBFile = OS.Path.join(oldDir, dbFilename);
|
|
|
|
newDBFile = OS.Path.join(newDir, dbFilename);
|
|
|
|
oldStorageDir = OS.Path.join(oldDir, "storage");
|
|
|
|
newStorageDir = OS.Path.join(newDir, "storage");
|
|
|
|
oldTranslatorsDir = OS.Path.join(oldDir, "translators");
|
|
|
|
newTranslatorsDir = OS.Path.join(newDir, "translators");
|
|
|
|
translatorName1 = 'a.js';
|
|
|
|
translatorName2 = 'b.js';
|
|
|
|
oldStorageDir1 = OS.Path.join(oldStorageDir, 'AAAAAAAA');
|
|
|
|
newStorageDir1 = OS.Path.join(newStorageDir, 'AAAAAAAA');
|
|
|
|
storageFile1 = 'test.pdf';
|
|
|
|
oldStorageDir2 = OS.Path.join(oldStorageDir, 'BBBBBBBB');
|
|
|
|
newStorageDir2 = OS.Path.join(newStorageDir, 'BBBBBBBB');
|
|
|
|
storageFile2 = 'test.html';
|
|
|
|
str1 = '1';
|
|
|
|
str2 = '2';
|
|
|
|
str3 = '3';
|
|
|
|
str4 = '4';
|
|
|
|
str5 = '5';
|
|
|
|
str6 = '6';
|
2016-11-27 03:41:26 +00:00
|
|
|
oldMigrationMarker = OS.Path.join(oldDir, Zotero.DataDirectory.MIGRATION_MARKER);
|
|
|
|
newMigrationMarker = OS.Path.join(newDir, Zotero.DataDirectory.MIGRATION_MARKER);
|
2016-11-24 06:19:52 +00:00
|
|
|
|
2016-11-27 03:41:26 +00:00
|
|
|
stubs.canMigrate = sinon.stub(Zotero.DataDirectory, "canMigrate").returns(true);
|
2017-06-12 11:14:36 +00:00
|
|
|
stubs.setDataDir = sinon.stub(Zotero.DataDirectory, "set");
|
|
|
|
stubs.isNewDirOnDifferentDrive = sinon.stub(Zotero.DataDirectory, 'isNewDirOnDifferentDrive').resolves(true);
|
Data directory migration
This adds a new button to the Advanced prefs to migrate the data directory to
$HOME/Zotero. The button only appears if the data directory is set to the
default location within a profile directory (including the other program from
the one running, even though that's technically stored as a custom data
directory).
On Mac/Linux, directories within the data directory are moved with /bin/mv. On
Windows, or if that fails, they're copied recursively using OS.File.move()
(which annoyingly doesn't reliably support directory moving). The former should
be instantaneous on most systems (unless the data directory or 'storage' were
on a different filesystem from $HOME).
If the database fails to transfer, migration fails and the data directory
setting remains on the old directory. If the database transfers but other files
fail, the data directory setting is updated. In both cases, the user is
encouraged to migrate remaining files manually with a button that reveals the
directories and quits the program.
This isn't yet tested on Linux or Windows, and migration isn't yet suggested
automatically.
Adds Zotero.File.reveal(), Zotero.File.directoryIsEmpty(), and
Zotero.File.moveDirectory().
2016-11-12 19:20:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(function* () {
|
2017-06-12 11:14:36 +00:00
|
|
|
stubs.setDataDir.reset();
|
Data directory migration
This adds a new button to the Advanced prefs to migrate the data directory to
$HOME/Zotero. The button only appears if the data directory is set to the
default location within a profile directory (including the other program from
the one running, even though that's technically stored as a custom data
directory).
On Mac/Linux, directories within the data directory are moved with /bin/mv. On
Windows, or if that fails, they're copied recursively using OS.File.move()
(which annoyingly doesn't reliably support directory moving). The former should
be instantaneous on most systems (unless the data directory or 'storage' were
on a different filesystem from $HOME).
If the database fails to transfer, migration fails and the data directory
setting remains on the old directory. If the database transfers but other files
fail, the data directory setting is updated. In both cases, the user is
encouraged to migrate remaining files manually with a button that reveals the
directories and quits the program.
This isn't yet tested on Linux or Windows, and migration isn't yet suggested
automatically.
Adds Zotero.File.reveal(), Zotero.File.directoryIsEmpty(), and
Zotero.File.moveDirectory().
2016-11-12 19:20:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function* () {
|
2016-11-19 23:52:10 +00:00
|
|
|
yield removeDir(oldDir);
|
|
|
|
yield removeDir(newDir);
|
2016-11-27 03:41:26 +00:00
|
|
|
Zotero.DataDirectory._cache(false);
|
|
|
|
yield Zotero.DataDirectory.init();
|
2016-11-24 06:19:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
after(function* () {
|
2017-06-12 11:14:36 +00:00
|
|
|
for (let key in stubs) {
|
|
|
|
try {
|
|
|
|
stubs[key].restore();
|
|
|
|
} catch(e) {}
|
|
|
|
}
|
Data directory migration
This adds a new button to the Advanced prefs to migrate the data directory to
$HOME/Zotero. The button only appears if the data directory is set to the
default location within a profile directory (including the other program from
the one running, even though that's technically stored as a custom data
directory).
On Mac/Linux, directories within the data directory are moved with /bin/mv. On
Windows, or if that fails, they're copied recursively using OS.File.move()
(which annoyingly doesn't reliably support directory moving). The former should
be instantaneous on most systems (unless the data directory or 'storage' were
on a different filesystem from $HOME).
If the database fails to transfer, migration fails and the data directory
setting remains on the old directory. If the database transfers but other files
fail, the data directory setting is updated. In both cases, the user is
encouraged to migrate remaining files manually with a button that reveals the
directories and quits the program.
This isn't yet tested on Linux or Windows, and migration isn't yet suggested
automatically.
Adds Zotero.File.reveal(), Zotero.File.directoryIsEmpty(), and
Zotero.File.moveDirectory().
2016-11-12 19:20:34 +00:00
|
|
|
});
|
|
|
|
|
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.
2017-02-22 09:56:49 +00:00
|
|
|
// Force non-mv mode
|
Data directory migration
This adds a new button to the Advanced prefs to migrate the data directory to
$HOME/Zotero. The button only appears if the data directory is set to the
default location within a profile directory (including the other program from
the one running, even though that's technically stored as a custom data
directory).
On Mac/Linux, directories within the data directory are moved with /bin/mv. On
Windows, or if that fails, they're copied recursively using OS.File.move()
(which annoyingly doesn't reliably support directory moving). The former should
be instantaneous on most systems (unless the data directory or 'storage' were
on a different filesystem from $HOME).
If the database fails to transfer, migration fails and the data directory
setting remains on the old directory. If the database transfers but other files
fail, the data directory setting is updated. In both cases, the user is
encouraged to migrate remaining files manually with a button that reveals the
directories and quits the program.
This isn't yet tested on Linux or Windows, and migration isn't yet suggested
automatically.
Adds Zotero.File.reveal(), Zotero.File.directoryIsEmpty(), and
Zotero.File.moveDirectory().
2016-11-12 19:20:34 +00:00
|
|
|
var disableCommandMode = function () {
|
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.
2017-02-22 09:56:49 +00:00
|
|
|
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")
|
2016-11-30 06:50:49 +00:00
|
|
|
.returns(false);
|
|
|
|
}
|
Data directory migration
This adds a new button to the Advanced prefs to migrate the data directory to
$HOME/Zotero. The button only appears if the data directory is set to the
default location within a profile directory (including the other program from
the one running, even though that's technically stored as a custom data
directory).
On Mac/Linux, directories within the data directory are moved with /bin/mv. On
Windows, or if that fails, they're copied recursively using OS.File.move()
(which annoyingly doesn't reliably support directory moving). The former should
be instantaneous on most systems (unless the data directory or 'storage' were
on a different filesystem from $HOME).
If the database fails to transfer, migration fails and the data directory
setting remains on the old directory. If the database transfers but other files
fail, the data directory setting is updated. In both cases, the user is
encouraged to migrate remaining files manually with a button that reveals the
directories and quits the program.
This isn't yet tested on Linux or Windows, and migration isn't yet suggested
automatically.
Adds Zotero.File.reveal(), Zotero.File.directoryIsEmpty(), and
Zotero.File.moveDirectory().
2016-11-12 19:20:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var resetCommandMode = function () {
|
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.
2017-02-22 09:56:49 +00:00
|
|
|
if (stubs.canMoveDirectoryWithCommand) {
|
|
|
|
stubs.canMoveDirectoryWithCommand.restore();
|
|
|
|
stubs.canMoveDirectoryWithCommand = undefined;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var resetFunctionMode = function () {
|
|
|
|
if (stubs.canMoveDirectoryWithFunction) {
|
|
|
|
stubs.canMoveDirectoryWithFunction.restore();
|
|
|
|
stubs.canMoveDirectoryWithFunction = undefined;
|
2016-11-30 06:50:49 +00:00
|
|
|
}
|
Data directory migration
This adds a new button to the Advanced prefs to migrate the data directory to
$HOME/Zotero. The button only appears if the data directory is set to the
default location within a profile directory (including the other program from
the one running, even though that's technically stored as a custom data
directory).
On Mac/Linux, directories within the data directory are moved with /bin/mv. On
Windows, or if that fails, they're copied recursively using OS.File.move()
(which annoyingly doesn't reliably support directory moving). The former should
be instantaneous on most systems (unless the data directory or 'storage' were
on a different filesystem from $HOME).
If the database fails to transfer, migration fails and the data directory
setting remains on the old directory. If the database transfers but other files
fail, the data directory setting is updated. In both cases, the user is
encouraged to migrate remaining files manually with a button that reveals the
directories and quits the program.
This isn't yet tested on Linux or Windows, and migration isn't yet suggested
automatically.
Adds Zotero.File.reveal(), Zotero.File.directoryIsEmpty(), and
Zotero.File.moveDirectory().
2016-11-12 19:20:34 +00:00
|
|
|
};
|
|
|
|
|
2016-11-22 06:40:39 +00:00
|
|
|
var populateDataDirectory = Zotero.Promise.coroutine(function* (dir, srcDir, automatic = false) {
|
Data directory migration
This adds a new button to the Advanced prefs to migrate the data directory to
$HOME/Zotero. The button only appears if the data directory is set to the
default location within a profile directory (including the other program from
the one running, even though that's technically stored as a custom data
directory).
On Mac/Linux, directories within the data directory are moved with /bin/mv. On
Windows, or if that fails, they're copied recursively using OS.File.move()
(which annoyingly doesn't reliably support directory moving). The former should
be instantaneous on most systems (unless the data directory or 'storage' were
on a different filesystem from $HOME).
If the database fails to transfer, migration fails and the data directory
setting remains on the old directory. If the database transfers but other files
fail, the data directory setting is updated. In both cases, the user is
encouraged to migrate remaining files manually with a button that reveals the
directories and quits the program.
This isn't yet tested on Linux or Windows, and migration isn't yet suggested
automatically.
Adds Zotero.File.reveal(), Zotero.File.directoryIsEmpty(), and
Zotero.File.moveDirectory().
2016-11-12 19:20:34 +00:00
|
|
|
yield OS.File.makeDir(dir, { unixMode: 0o755 });
|
|
|
|
let storageDir = OS.Path.join(dir, 'storage');
|
|
|
|
let storageDir1 = OS.Path.join(storageDir, 'AAAAAAAA');
|
|
|
|
let storageDir2 = OS.Path.join(storageDir, 'BBBBBBBB');
|
|
|
|
let translatorsDir = OS.Path.join(dir, 'translators');
|
2016-11-27 03:41:26 +00:00
|
|
|
let migrationMarker = OS.Path.join(dir, Zotero.DataDirectory.MIGRATION_MARKER);
|
Data directory migration
This adds a new button to the Advanced prefs to migrate the data directory to
$HOME/Zotero. The button only appears if the data directory is set to the
default location within a profile directory (including the other program from
the one running, even though that's technically stored as a custom data
directory).
On Mac/Linux, directories within the data directory are moved with /bin/mv. On
Windows, or if that fails, they're copied recursively using OS.File.move()
(which annoyingly doesn't reliably support directory moving). The former should
be instantaneous on most systems (unless the data directory or 'storage' were
on a different filesystem from $HOME).
If the database fails to transfer, migration fails and the data directory
setting remains on the old directory. If the database transfers but other files
fail, the data directory setting is updated. In both cases, the user is
encouraged to migrate remaining files manually with a button that reveals the
directories and quits the program.
This isn't yet tested on Linux or Windows, and migration isn't yet suggested
automatically.
Adds Zotero.File.reveal(), Zotero.File.directoryIsEmpty(), and
Zotero.File.moveDirectory().
2016-11-12 19:20:34 +00:00
|
|
|
|
|
|
|
// Database
|
|
|
|
yield Zotero.File.putContentsAsync(OS.Path.join(dir, dbFilename), str1);
|
|
|
|
// Database backup
|
|
|
|
yield Zotero.File.putContentsAsync(OS.Path.join(dir, dbFilename + '.bak'), str2);
|
|
|
|
// 'storage' directory
|
|
|
|
yield OS.File.makeDir(storageDir, { unixMode: 0o755 });
|
|
|
|
// 'storage' folders
|
|
|
|
yield OS.File.makeDir(storageDir1, { unixMode: 0o755 });
|
|
|
|
yield Zotero.File.putContentsAsync(OS.Path.join(storageDir1, storageFile1), str2);
|
|
|
|
yield OS.File.makeDir(storageDir2, { unixMode: 0o755 });
|
|
|
|
yield Zotero.File.putContentsAsync(OS.Path.join(storageDir2, storageFile2), str3);
|
|
|
|
// 'translators' and some translators
|
|
|
|
yield OS.File.makeDir(translatorsDir, { unixMode: 0o755 });
|
|
|
|
yield Zotero.File.putContentsAsync(OS.Path.join(translatorsDir, translatorName1), str4);
|
|
|
|
yield Zotero.File.putContentsAsync(OS.Path.join(translatorsDir, translatorName2), str5);
|
|
|
|
// Migration marker
|
2016-11-22 06:40:39 +00:00
|
|
|
yield Zotero.File.putContentsAsync(
|
|
|
|
migrationMarker,
|
|
|
|
JSON.stringify({
|
|
|
|
sourceDir: srcDir || dir,
|
|
|
|
automatic
|
|
|
|
})
|
|
|
|
);
|
Data directory migration
This adds a new button to the Advanced prefs to migrate the data directory to
$HOME/Zotero. The button only appears if the data directory is set to the
default location within a profile directory (including the other program from
the one running, even though that's technically stored as a custom data
directory).
On Mac/Linux, directories within the data directory are moved with /bin/mv. On
Windows, or if that fails, they're copied recursively using OS.File.move()
(which annoyingly doesn't reliably support directory moving). The former should
be instantaneous on most systems (unless the data directory or 'storage' were
on a different filesystem from $HOME).
If the database fails to transfer, migration fails and the data directory
setting remains on the old directory. If the database transfers but other files
fail, the data directory setting is updated. In both cases, the user is
encouraged to migrate remaining files manually with a button that reveals the
directories and quits the program.
This isn't yet tested on Linux or Windows, and migration isn't yet suggested
automatically.
Adds Zotero.File.reveal(), Zotero.File.directoryIsEmpty(), and
Zotero.File.moveDirectory().
2016-11-12 19:20:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
var checkMigration = Zotero.Promise.coroutine(function* (options = {}) {
|
|
|
|
if (!options.skipOldDir) {
|
|
|
|
assert.isFalse(yield OS.File.exists(oldDir));
|
|
|
|
}
|
|
|
|
yield assert.eventually.equal(Zotero.File.getContentsAsync(newDBFile), str1);
|
|
|
|
yield assert.eventually.equal(Zotero.File.getContentsAsync(newDBFile + '.bak'), str2);
|
|
|
|
if (!options.skipStorageFile1) {
|
|
|
|
yield assert.eventually.equal(
|
|
|
|
Zotero.File.getContentsAsync(OS.Path.join(newStorageDir1, storageFile1)), str2
|
|
|
|
);
|
|
|
|
}
|
|
|
|
yield assert.eventually.equal(
|
|
|
|
Zotero.File.getContentsAsync(OS.Path.join(newStorageDir2, storageFile2)), str3
|
|
|
|
);
|
|
|
|
yield assert.eventually.equal(
|
|
|
|
Zotero.File.getContentsAsync(OS.Path.join(newTranslatorsDir, translatorName1)), str4
|
|
|
|
);
|
|
|
|
yield assert.eventually.equal(
|
|
|
|
Zotero.File.getContentsAsync(OS.Path.join(newTranslatorsDir, translatorName2)), str5
|
|
|
|
);
|
|
|
|
if (!options.skipNewMarker) {
|
|
|
|
assert.isFalse(yield OS.File.exists(newMigrationMarker));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!options.skipSetDataDirectory) {
|
2016-11-24 06:19:52 +00:00
|
|
|
assert.ok(stubs.setDataDir.calledOnce);
|
|
|
|
assert.ok(stubs.setDataDir.calledWith(newDir));
|
Data directory migration
This adds a new button to the Advanced prefs to migrate the data directory to
$HOME/Zotero. The button only appears if the data directory is set to the
default location within a profile directory (including the other program from
the one running, even though that's technically stored as a custom data
directory).
On Mac/Linux, directories within the data directory are moved with /bin/mv. On
Windows, or if that fails, they're copied recursively using OS.File.move()
(which annoyingly doesn't reliably support directory moving). The former should
be instantaneous on most systems (unless the data directory or 'storage' were
on a different filesystem from $HOME).
If the database fails to transfer, migration fails and the data directory
setting remains on the old directory. If the database transfers but other files
fail, the data directory setting is updated. In both cases, the user is
encouraged to migrate remaining files manually with a button that reveals the
directories and quits the program.
This isn't yet tested on Linux or Windows, and migration isn't yet suggested
automatically.
Adds Zotero.File.reveal(), Zotero.File.directoryIsEmpty(), and
Zotero.File.moveDirectory().
2016-11-12 19:20:34 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-11-27 03:41:26 +00:00
|
|
|
describe("#checkForMigration()", function () {
|
2016-11-24 06:19:52 +00:00
|
|
|
let fileMoveStub;
|
Data directory migration
This adds a new button to the Advanced prefs to migrate the data directory to
$HOME/Zotero. The button only appears if the data directory is set to the
default location within a profile directory (including the other program from
the one running, even though that's technically stored as a custom data
directory).
On Mac/Linux, directories within the data directory are moved with /bin/mv. On
Windows, or if that fails, they're copied recursively using OS.File.move()
(which annoyingly doesn't reliably support directory moving). The former should
be instantaneous on most systems (unless the data directory or 'storage' were
on a different filesystem from $HOME).
If the database fails to transfer, migration fails and the data directory
setting remains on the old directory. If the database transfers but other files
fail, the data directory setting is updated. In both cases, the user is
encouraged to migrate remaining files manually with a button that reveals the
directories and quits the program.
This isn't yet tested on Linux or Windows, and migration isn't yet suggested
automatically.
Adds Zotero.File.reveal(), Zotero.File.directoryIsEmpty(), and
Zotero.File.moveDirectory().
2016-11-12 19:20:34 +00:00
|
|
|
|
2016-11-30 06:50:49 +00:00
|
|
|
beforeEach(function () {
|
Data directory migration
This adds a new button to the Advanced prefs to migrate the data directory to
$HOME/Zotero. The button only appears if the data directory is set to the
default location within a profile directory (including the other program from
the one running, even though that's technically stored as a custom data
directory).
On Mac/Linux, directories within the data directory are moved with /bin/mv. On
Windows, or if that fails, they're copied recursively using OS.File.move()
(which annoyingly doesn't reliably support directory moving). The former should
be instantaneous on most systems (unless the data directory or 'storage' were
on a different filesystem from $HOME).
If the database fails to transfer, migration fails and the data directory
setting remains on the old directory. If the database transfers but other files
fail, the data directory setting is updated. In both cases, the user is
encouraged to migrate remaining files manually with a button that reveals the
directories and quits the program.
This isn't yet tested on Linux or Windows, and migration isn't yet suggested
automatically.
Adds Zotero.File.reveal(), Zotero.File.directoryIsEmpty(), and
Zotero.File.moveDirectory().
2016-11-12 19:20:34 +00:00
|
|
|
disableCommandMode();
|
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.
2017-02-22 09:56:49 +00:00
|
|
|
disableFunctionMode();
|
Data directory migration
This adds a new button to the Advanced prefs to migrate the data directory to
$HOME/Zotero. The button only appears if the data directory is set to the
default location within a profile directory (including the other program from
the one running, even though that's technically stored as a custom data
directory).
On Mac/Linux, directories within the data directory are moved with /bin/mv. On
Windows, or if that fails, they're copied recursively using OS.File.move()
(which annoyingly doesn't reliably support directory moving). The former should
be instantaneous on most systems (unless the data directory or 'storage' were
on a different filesystem from $HOME).
If the database fails to transfer, migration fails and the data directory
setting remains on the old directory. If the database transfers but other files
fail, the data directory setting is updated. In both cases, the user is
encouraged to migrate remaining files manually with a button that reveals the
directories and quits the program.
This isn't yet tested on Linux or Windows, and migration isn't yet suggested
automatically.
Adds Zotero.File.reveal(), Zotero.File.directoryIsEmpty(), and
Zotero.File.moveDirectory().
2016-11-12 19:20:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
resetCommandMode();
|
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.
2017-02-22 09:56:49 +00:00
|
|
|
resetFunctionMode();
|
Data directory migration
This adds a new button to the Advanced prefs to migrate the data directory to
$HOME/Zotero. The button only appears if the data directory is set to the
default location within a profile directory (including the other program from
the one running, even though that's technically stored as a custom data
directory).
On Mac/Linux, directories within the data directory are moved with /bin/mv. On
Windows, or if that fails, they're copied recursively using OS.File.move()
(which annoyingly doesn't reliably support directory moving). The former should
be instantaneous on most systems (unless the data directory or 'storage' were
on a different filesystem from $HOME).
If the database fails to transfer, migration fails and the data directory
setting remains on the old directory. If the database transfers but other files
fail, the data directory setting is updated. In both cases, the user is
encouraged to migrate remaining files manually with a button that reveals the
directories and quits the program.
This isn't yet tested on Linux or Windows, and migration isn't yet suggested
automatically.
Adds Zotero.File.reveal(), Zotero.File.directoryIsEmpty(), and
Zotero.File.moveDirectory().
2016-11-12 19:20:34 +00:00
|
|
|
});
|
|
|
|
|
2016-11-22 06:40:39 +00:00
|
|
|
var tests = [];
|
|
|
|
function add(desc, fn) {
|
|
|
|
tests.push([desc, fn]);
|
|
|
|
}
|
|
|
|
|
2016-11-30 06:50:49 +00:00
|
|
|
it("should skip automatic migration if target directory exists and is non-empty", function* () {
|
|
|
|
resetCommandMode();
|
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.
2017-02-22 09:56:49 +00:00
|
|
|
resetFunctionMode();
|
2016-11-30 06:50:49 +00:00
|
|
|
|
|
|
|
yield populateDataDirectory(oldDir);
|
|
|
|
yield OS.File.remove(oldMigrationMarker);
|
|
|
|
yield OS.File.makeDir(newDir, { unixMode: 0o755 });
|
|
|
|
yield Zotero.File.putContentsAsync(OS.Path.join(newDir, 'a'), '');
|
|
|
|
|
|
|
|
yield assert.eventually.isFalse(Zotero.DataDirectory.checkForMigration(oldDir, newDir));
|
|
|
|
});
|
|
|
|
|
2017-06-12 11:14:36 +00:00
|
|
|
it("should skip automatic migration and show prompt if target directory is on a different drive", function* () {
|
|
|
|
resetCommandMode();
|
|
|
|
resetFunctionMode();
|
|
|
|
|
|
|
|
yield populateDataDirectory(oldDir);
|
|
|
|
yield OS.File.remove(oldMigrationMarker);
|
|
|
|
|
|
|
|
stubs.isNewDirOnDifferentDrive.resolves(true);
|
|
|
|
|
|
|
|
var promise = waitForDialog(function (dialog) {
|
|
|
|
assert.include(
|
|
|
|
dialog.document.documentElement.textContent,
|
|
|
|
Zotero.getString(`dataDir.migration.failure.full.automatic.newDirOnDifferentDrive`, Zotero.clientName)
|
|
|
|
);
|
|
|
|
}, 'cancel');
|
|
|
|
|
|
|
|
yield assert.eventually.isNotOk(Zotero.DataDirectory.checkForMigration(oldDir, newDir));
|
|
|
|
yield promise;
|
|
|
|
|
|
|
|
stubs.isNewDirOnDifferentDrive.resolves(false);
|
|
|
|
});
|
|
|
|
|
2016-11-22 06:40:39 +00:00
|
|
|
add("should show error on partial failure", function (automatic) {
|
|
|
|
return function* () {
|
|
|
|
yield populateDataDirectory(oldDir, null, automatic);
|
|
|
|
|
|
|
|
let origFunc = OS.File.move;
|
2017-05-31 15:44:35 +00:00
|
|
|
let fileMoveStub = sinon.stub(OS.File, "move").callsFake(function () {
|
2016-11-22 06:40:39 +00:00
|
|
|
if (OS.Path.basename(arguments[0]) == storageFile1) {
|
|
|
|
return Zotero.Promise.reject(new Error("Error"));
|
2016-11-20 06:54:09 +00:00
|
|
|
}
|
|
|
|
else {
|
2017-06-23 08:59:48 +00:00
|
|
|
return origFunc(...arguments);
|
2016-11-20 06:54:09 +00:00
|
|
|
}
|
2016-11-22 06:40:39 +00:00
|
|
|
});
|
2016-11-24 06:19:52 +00:00
|
|
|
let stub1 = sinon.stub(Zotero.File, "reveal").returns(Zotero.Promise.resolve());
|
|
|
|
let stub2 = sinon.stub(Zotero.Utilities.Internal, "quitZotero");
|
2016-11-22 06:40:39 +00:00
|
|
|
|
|
|
|
var promise2;
|
|
|
|
// Click "Try Again" the first time, and then "Show Directories and Quit Zotero"
|
|
|
|
var promise = waitForDialog(function (dialog) {
|
|
|
|
promise2 = waitForDialog(null, 'extra1');
|
|
|
|
|
|
|
|
// Make sure we're displaying the right message for this mode (automatic or manual)
|
|
|
|
Components.utils.import("resource://zotero/config.js");
|
|
|
|
assert.include(
|
|
|
|
dialog.document.documentElement.textContent,
|
|
|
|
Zotero.getString(
|
|
|
|
`dataDir.migration.failure.partial.${automatic ? 'automatic' : 'manual'}.text`,
|
|
|
|
[ZOTERO_CONFIG.CLIENT_NAME, Zotero.appName]
|
|
|
|
)
|
|
|
|
);
|
|
|
|
});
|
2016-11-27 03:41:26 +00:00
|
|
|
yield Zotero.DataDirectory.checkForMigration(oldDir, newDir);
|
2016-11-22 06:40:39 +00:00
|
|
|
yield promise;
|
|
|
|
yield promise2;
|
|
|
|
|
2016-11-24 06:19:52 +00:00
|
|
|
assert.isTrue(stub1.calledTwice);
|
|
|
|
assert.isTrue(stub1.getCall(0).calledWith(oldStorageDir));
|
|
|
|
assert.isTrue(stub1.getCall(1).calledWith(newDBFile));
|
|
|
|
assert.isTrue(stub2.called);
|
2016-11-22 06:40:39 +00:00
|
|
|
|
2016-11-24 06:19:52 +00:00
|
|
|
fileMoveStub.restore();
|
|
|
|
stub1.restore();
|
|
|
|
stub2.restore();
|
2016-11-22 06:40:39 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
add("should show error on full failure", function (automatic) {
|
|
|
|
return function* () {
|
|
|
|
yield populateDataDirectory(oldDir, null, automatic);
|
|
|
|
|
|
|
|
let origFunc = OS.File.move;
|
2017-05-31 15:44:35 +00:00
|
|
|
let stub1 = sinon.stub(OS.File, "move").callsFake(function () {
|
2016-11-22 06:40:39 +00:00
|
|
|
if (OS.Path.basename(arguments[0]) == dbFilename) {
|
|
|
|
return Zotero.Promise.reject(new Error("Error"));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return origFunc(...arguments);
|
|
|
|
}
|
|
|
|
});
|
2016-11-24 06:19:52 +00:00
|
|
|
let stub2 = sinon.stub(Zotero.File, "reveal").returns(Zotero.Promise.resolve());
|
|
|
|
let stub3 = sinon.stub(Zotero.Utilities.Internal, "quitZotero");
|
2016-11-22 06:40:39 +00:00
|
|
|
|
|
|
|
var promise = waitForDialog(function (dialog) {
|
|
|
|
// Make sure we're displaying the right message for this mode (automatic or manual)
|
|
|
|
Components.utils.import("resource://zotero/config.js");
|
|
|
|
assert.include(
|
|
|
|
dialog.document.documentElement.textContent,
|
|
|
|
Zotero.getString(
|
|
|
|
`dataDir.migration.failure.full.${automatic ? 'automatic' : 'manual'}.text1`,
|
|
|
|
ZOTERO_CONFIG.CLIENT_NAME
|
|
|
|
)
|
|
|
|
);
|
|
|
|
});
|
2016-11-27 03:41:26 +00:00
|
|
|
yield Zotero.DataDirectory.checkForMigration(oldDir, newDir);
|
2016-11-22 06:40:39 +00:00
|
|
|
yield promise;
|
|
|
|
|
2016-11-24 06:19:52 +00:00
|
|
|
assert.isTrue(stub2.calledOnce);
|
|
|
|
assert.isTrue(stub2.calledWith(oldDir));
|
|
|
|
assert.isTrue(stub3.called);
|
2016-11-22 06:40:39 +00:00
|
|
|
|
2016-11-24 06:19:52 +00:00
|
|
|
stub1.restore();
|
|
|
|
stub2.restore();
|
2016-11-22 06:40:39 +00:00
|
|
|
stub3.restore();
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("automatic mode", function () {
|
|
|
|
tests.forEach(arr => {
|
|
|
|
it(arr[0], arr[1](true));
|
2016-11-21 09:54:01 +00:00
|
|
|
});
|
Data directory migration
This adds a new button to the Advanced prefs to migrate the data directory to
$HOME/Zotero. The button only appears if the data directory is set to the
default location within a profile directory (including the other program from
the one running, even though that's technically stored as a custom data
directory).
On Mac/Linux, directories within the data directory are moved with /bin/mv. On
Windows, or if that fails, they're copied recursively using OS.File.move()
(which annoyingly doesn't reliably support directory moving). The former should
be instantaneous on most systems (unless the data directory or 'storage' were
on a different filesystem from $HOME).
If the database fails to transfer, migration fails and the data directory
setting remains on the old directory. If the database transfers but other files
fail, the data directory setting is updated. In both cases, the user is
encouraged to migrate remaining files manually with a button that reveals the
directories and quits the program.
This isn't yet tested on Linux or Windows, and migration isn't yet suggested
automatically.
Adds Zotero.File.reveal(), Zotero.File.directoryIsEmpty(), and
Zotero.File.moveDirectory().
2016-11-12 19:20:34 +00:00
|
|
|
});
|
|
|
|
|
2016-11-22 06:40:39 +00:00
|
|
|
describe("manual mode", function () {
|
|
|
|
tests.forEach(arr => {
|
|
|
|
it(arr[0], arr[1](false));
|
Data directory migration
This adds a new button to the Advanced prefs to migrate the data directory to
$HOME/Zotero. The button only appears if the data directory is set to the
default location within a profile directory (including the other program from
the one running, even though that's technically stored as a custom data
directory).
On Mac/Linux, directories within the data directory are moved with /bin/mv. On
Windows, or if that fails, they're copied recursively using OS.File.move()
(which annoyingly doesn't reliably support directory moving). The former should
be instantaneous on most systems (unless the data directory or 'storage' were
on a different filesystem from $HOME).
If the database fails to transfer, migration fails and the data directory
setting remains on the old directory. If the database transfers but other files
fail, the data directory setting is updated. In both cases, the user is
encouraged to migrate remaining files manually with a button that reveals the
directories and quits the program.
This isn't yet tested on Linux or Windows, and migration isn't yet suggested
automatically.
Adds Zotero.File.reveal(), Zotero.File.directoryIsEmpty(), and
Zotero.File.moveDirectory().
2016-11-12 19:20:34 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should remove marker if old directory doesn't exist", function* () {
|
|
|
|
yield populateDataDirectory(newDir, oldDir);
|
2016-11-27 03:41:26 +00:00
|
|
|
yield Zotero.DataDirectory.checkForMigration(newDir, newDir);
|
Data directory migration
This adds a new button to the Advanced prefs to migrate the data directory to
$HOME/Zotero. The button only appears if the data directory is set to the
default location within a profile directory (including the other program from
the one running, even though that's technically stored as a custom data
directory).
On Mac/Linux, directories within the data directory are moved with /bin/mv. On
Windows, or if that fails, they're copied recursively using OS.File.move()
(which annoyingly doesn't reliably support directory moving). The former should
be instantaneous on most systems (unless the data directory or 'storage' were
on a different filesystem from $HOME).
If the database fails to transfer, migration fails and the data directory
setting remains on the old directory. If the database transfers but other files
fail, the data directory setting is updated. In both cases, the user is
encouraged to migrate remaining files manually with a button that reveals the
directories and quits the program.
This isn't yet tested on Linux or Windows, and migration isn't yet suggested
automatically.
Adds Zotero.File.reveal(), Zotero.File.directoryIsEmpty(), and
Zotero.File.moveDirectory().
2016-11-12 19:20:34 +00:00
|
|
|
yield checkMigration({
|
|
|
|
skipSetDataDirectory: true
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-11-27 03:41:26 +00:00
|
|
|
describe("#migrate()", function () {
|
Data directory migration
This adds a new button to the Advanced prefs to migrate the data directory to
$HOME/Zotero. The button only appears if the data directory is set to the
default location within a profile directory (including the other program from
the one running, even though that's technically stored as a custom data
directory).
On Mac/Linux, directories within the data directory are moved with /bin/mv. On
Windows, or if that fails, they're copied recursively using OS.File.move()
(which annoyingly doesn't reliably support directory moving). The former should
be instantaneous on most systems (unless the data directory or 'storage' were
on a different filesystem from $HOME).
If the database fails to transfer, migration fails and the data directory
setting remains on the old directory. If the database transfers but other files
fail, the data directory setting is updated. In both cases, the user is
encouraged to migrate remaining files manually with a button that reveals the
directories and quits the program.
This isn't yet tested on Linux or Windows, and migration isn't yet suggested
automatically.
Adds Zotero.File.reveal(), Zotero.File.directoryIsEmpty(), and
Zotero.File.moveDirectory().
2016-11-12 19:20:34 +00:00
|
|
|
// Define tests and store for running in non-mv mode
|
|
|
|
var tests = [];
|
|
|
|
function add(desc, fn) {
|
|
|
|
it(desc, fn);
|
|
|
|
tests.push([desc, fn]);
|
|
|
|
}
|
|
|
|
|
|
|
|
add("should move all files and folders", function* () {
|
|
|
|
yield populateDataDirectory(oldDir);
|
2016-11-27 03:41:26 +00:00
|
|
|
yield Zotero.DataDirectory.migrate(oldDir, newDir);
|
Data directory migration
This adds a new button to the Advanced prefs to migrate the data directory to
$HOME/Zotero. The button only appears if the data directory is set to the
default location within a profile directory (including the other program from
the one running, even though that's technically stored as a custom data
directory).
On Mac/Linux, directories within the data directory are moved with /bin/mv. On
Windows, or if that fails, they're copied recursively using OS.File.move()
(which annoyingly doesn't reliably support directory moving). The former should
be instantaneous on most systems (unless the data directory or 'storage' were
on a different filesystem from $HOME).
If the database fails to transfer, migration fails and the data directory
setting remains on the old directory. If the database transfers but other files
fail, the data directory setting is updated. In both cases, the user is
encouraged to migrate remaining files manually with a button that reveals the
directories and quits the program.
This isn't yet tested on Linux or Windows, and migration isn't yet suggested
automatically.
Adds Zotero.File.reveal(), Zotero.File.directoryIsEmpty(), and
Zotero.File.moveDirectory().
2016-11-12 19:20:34 +00:00
|
|
|
yield checkMigration();
|
|
|
|
});
|
|
|
|
|
|
|
|
add("should resume partial migration with just marker copied", function* () {
|
|
|
|
yield populateDataDirectory(oldDir);
|
|
|
|
yield OS.File.makeDir(newDir, { unixMode: 0o755 });
|
|
|
|
|
|
|
|
yield OS.File.copy(oldMigrationMarker, newMigrationMarker);
|
|
|
|
|
2016-11-27 03:41:26 +00:00
|
|
|
yield Zotero.DataDirectory.migrate(oldDir, newDir, true);
|
Data directory migration
This adds a new button to the Advanced prefs to migrate the data directory to
$HOME/Zotero. The button only appears if the data directory is set to the
default location within a profile directory (including the other program from
the one running, even though that's technically stored as a custom data
directory).
On Mac/Linux, directories within the data directory are moved with /bin/mv. On
Windows, or if that fails, they're copied recursively using OS.File.move()
(which annoyingly doesn't reliably support directory moving). The former should
be instantaneous on most systems (unless the data directory or 'storage' were
on a different filesystem from $HOME).
If the database fails to transfer, migration fails and the data directory
setting remains on the old directory. If the database transfers but other files
fail, the data directory setting is updated. In both cases, the user is
encouraged to migrate remaining files manually with a button that reveals the
directories and quits the program.
This isn't yet tested on Linux or Windows, and migration isn't yet suggested
automatically.
Adds Zotero.File.reveal(), Zotero.File.directoryIsEmpty(), and
Zotero.File.moveDirectory().
2016-11-12 19:20:34 +00:00
|
|
|
yield checkMigration();
|
|
|
|
});
|
|
|
|
|
|
|
|
add("should resume partial migration with database moved", function* () {
|
|
|
|
yield populateDataDirectory(oldDir);
|
|
|
|
yield OS.File.makeDir(newDir, { unixMode: 0o755 });
|
|
|
|
|
|
|
|
yield OS.File.copy(oldMigrationMarker, newMigrationMarker);
|
|
|
|
yield OS.File.move(OS.Path.join(oldDir, dbFilename), OS.Path.join(newDir, dbFilename));
|
|
|
|
|
2016-11-27 03:41:26 +00:00
|
|
|
yield Zotero.DataDirectory.migrate(oldDir, newDir, true);
|
Data directory migration
This adds a new button to the Advanced prefs to migrate the data directory to
$HOME/Zotero. The button only appears if the data directory is set to the
default location within a profile directory (including the other program from
the one running, even though that's technically stored as a custom data
directory).
On Mac/Linux, directories within the data directory are moved with /bin/mv. On
Windows, or if that fails, they're copied recursively using OS.File.move()
(which annoyingly doesn't reliably support directory moving). The former should
be instantaneous on most systems (unless the data directory or 'storage' were
on a different filesystem from $HOME).
If the database fails to transfer, migration fails and the data directory
setting remains on the old directory. If the database transfers but other files
fail, the data directory setting is updated. In both cases, the user is
encouraged to migrate remaining files manually with a button that reveals the
directories and quits the program.
This isn't yet tested on Linux or Windows, and migration isn't yet suggested
automatically.
Adds Zotero.File.reveal(), Zotero.File.directoryIsEmpty(), and
Zotero.File.moveDirectory().
2016-11-12 19:20:34 +00:00
|
|
|
yield checkMigration();
|
|
|
|
});
|
|
|
|
|
|
|
|
add("should resume partial migration with some storage directories moved", function* () {
|
|
|
|
yield populateDataDirectory(oldDir);
|
|
|
|
yield populateDataDirectory(newDir, oldDir);
|
|
|
|
|
|
|
|
// Moved: DB, DB backup, one storage dir
|
|
|
|
// Not moved: one storage dir, translators dir
|
|
|
|
yield OS.File.remove(oldDBFile);
|
|
|
|
yield OS.File.remove(oldDBFile + '.bak');
|
2016-11-19 23:52:10 +00:00
|
|
|
yield removeDir(oldStorageDir1);
|
|
|
|
yield removeDir(newTranslatorsDir);
|
|
|
|
yield removeDir(newStorageDir2);
|
Data directory migration
This adds a new button to the Advanced prefs to migrate the data directory to
$HOME/Zotero. The button only appears if the data directory is set to the
default location within a profile directory (including the other program from
the one running, even though that's technically stored as a custom data
directory).
On Mac/Linux, directories within the data directory are moved with /bin/mv. On
Windows, or if that fails, they're copied recursively using OS.File.move()
(which annoyingly doesn't reliably support directory moving). The former should
be instantaneous on most systems (unless the data directory or 'storage' were
on a different filesystem from $HOME).
If the database fails to transfer, migration fails and the data directory
setting remains on the old directory. If the database transfers but other files
fail, the data directory setting is updated. In both cases, the user is
encouraged to migrate remaining files manually with a button that reveals the
directories and quits the program.
This isn't yet tested on Linux or Windows, and migration isn't yet suggested
automatically.
Adds Zotero.File.reveal(), Zotero.File.directoryIsEmpty(), and
Zotero.File.moveDirectory().
2016-11-12 19:20:34 +00:00
|
|
|
|
2016-11-27 03:41:26 +00:00
|
|
|
yield Zotero.DataDirectory.migrate(oldDir, newDir, true);
|
Data directory migration
This adds a new button to the Advanced prefs to migrate the data directory to
$HOME/Zotero. The button only appears if the data directory is set to the
default location within a profile directory (including the other program from
the one running, even though that's technically stored as a custom data
directory).
On Mac/Linux, directories within the data directory are moved with /bin/mv. On
Windows, or if that fails, they're copied recursively using OS.File.move()
(which annoyingly doesn't reliably support directory moving). The former should
be instantaneous on most systems (unless the data directory or 'storage' were
on a different filesystem from $HOME).
If the database fails to transfer, migration fails and the data directory
setting remains on the old directory. If the database transfers but other files
fail, the data directory setting is updated. In both cases, the user is
encouraged to migrate remaining files manually with a button that reveals the
directories and quits the program.
This isn't yet tested on Linux or Windows, and migration isn't yet suggested
automatically.
Adds Zotero.File.reveal(), Zotero.File.directoryIsEmpty(), and
Zotero.File.moveDirectory().
2016-11-12 19:20:34 +00:00
|
|
|
yield checkMigration();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Run all tests again without using mv
|
|
|
|
//
|
|
|
|
// On Windows these will just be duplicates of the above tests.
|
|
|
|
describe("non-mv mode", function () {
|
|
|
|
tests.forEach(arr => {
|
|
|
|
it(arr[0] + " [non-mv]", arr[1]);
|
|
|
|
});
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
disableCommandMode();
|
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.
2017-02-22 09:56:49 +00:00
|
|
|
disableFunctionMode();
|
Data directory migration
This adds a new button to the Advanced prefs to migrate the data directory to
$HOME/Zotero. The button only appears if the data directory is set to the
default location within a profile directory (including the other program from
the one running, even though that's technically stored as a custom data
directory).
On Mac/Linux, directories within the data directory are moved with /bin/mv. On
Windows, or if that fails, they're copied recursively using OS.File.move()
(which annoyingly doesn't reliably support directory moving). The former should
be instantaneous on most systems (unless the data directory or 'storage' were
on a different filesystem from $HOME).
If the database fails to transfer, migration fails and the data directory
setting remains on the old directory. If the database transfers but other files
fail, the data directory setting is updated. In both cases, the user is
encouraged to migrate remaining files manually with a button that reveals the
directories and quits the program.
This isn't yet tested on Linux or Windows, and migration isn't yet suggested
automatically.
Adds Zotero.File.reveal(), Zotero.File.directoryIsEmpty(), and
Zotero.File.moveDirectory().
2016-11-12 19:20:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
resetCommandMode();
|
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.
2017-02-22 09:56:49 +00:00
|
|
|
resetFunctionMode();
|
Data directory migration
This adds a new button to the Advanced prefs to migrate the data directory to
$HOME/Zotero. The button only appears if the data directory is set to the
default location within a profile directory (including the other program from
the one running, even though that's technically stored as a custom data
directory).
On Mac/Linux, directories within the data directory are moved with /bin/mv. On
Windows, or if that fails, they're copied recursively using OS.File.move()
(which annoyingly doesn't reliably support directory moving). The former should
be instantaneous on most systems (unless the data directory or 'storage' were
on a different filesystem from $HOME).
If the database fails to transfer, migration fails and the data directory
setting remains on the old directory. If the database transfers but other files
fail, the data directory setting is updated. In both cases, the user is
encouraged to migrate remaining files manually with a button that reveals the
directories and quits the program.
This isn't yet tested on Linux or Windows, and migration isn't yet suggested
automatically.
Adds Zotero.File.reveal(), Zotero.File.directoryIsEmpty(), and
Zotero.File.moveDirectory().
2016-11-12 19:20:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should handle partial failure", function* () {
|
|
|
|
yield populateDataDirectory(oldDir);
|
|
|
|
|
|
|
|
let origFunc = OS.File.move;
|
2017-05-31 15:44:35 +00:00
|
|
|
let stub1 = sinon.stub(OS.File, "move").callsFake(function () {
|
Data directory migration
This adds a new button to the Advanced prefs to migrate the data directory to
$HOME/Zotero. The button only appears if the data directory is set to the
default location within a profile directory (including the other program from
the one running, even though that's technically stored as a custom data
directory).
On Mac/Linux, directories within the data directory are moved with /bin/mv. On
Windows, or if that fails, they're copied recursively using OS.File.move()
(which annoyingly doesn't reliably support directory moving). The former should
be instantaneous on most systems (unless the data directory or 'storage' were
on a different filesystem from $HOME).
If the database fails to transfer, migration fails and the data directory
setting remains on the old directory. If the database transfers but other files
fail, the data directory setting is updated. In both cases, the user is
encouraged to migrate remaining files manually with a button that reveals the
directories and quits the program.
This isn't yet tested on Linux or Windows, and migration isn't yet suggested
automatically.
Adds Zotero.File.reveal(), Zotero.File.directoryIsEmpty(), and
Zotero.File.moveDirectory().
2016-11-12 19:20:34 +00:00
|
|
|
if (OS.Path.basename(arguments[0]) == storageFile1) {
|
|
|
|
return Zotero.Promise.reject(new Error("Error"));
|
|
|
|
}
|
|
|
|
else {
|
2017-06-23 08:59:48 +00:00
|
|
|
return origFunc(...arguments);
|
Data directory migration
This adds a new button to the Advanced prefs to migrate the data directory to
$HOME/Zotero. The button only appears if the data directory is set to the
default location within a profile directory (including the other program from
the one running, even though that's technically stored as a custom data
directory).
On Mac/Linux, directories within the data directory are moved with /bin/mv. On
Windows, or if that fails, they're copied recursively using OS.File.move()
(which annoyingly doesn't reliably support directory moving). The former should
be instantaneous on most systems (unless the data directory or 'storage' were
on a different filesystem from $HOME).
If the database fails to transfer, migration fails and the data directory
setting remains on the old directory. If the database transfers but other files
fail, the data directory setting is updated. In both cases, the user is
encouraged to migrate remaining files manually with a button that reveals the
directories and quits the program.
This isn't yet tested on Linux or Windows, and migration isn't yet suggested
automatically.
Adds Zotero.File.reveal(), Zotero.File.directoryIsEmpty(), and
Zotero.File.moveDirectory().
2016-11-12 19:20:34 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-11-27 03:41:26 +00:00
|
|
|
yield Zotero.DataDirectory.migrate(oldDir, newDir);
|
Data directory migration
This adds a new button to the Advanced prefs to migrate the data directory to
$HOME/Zotero. The button only appears if the data directory is set to the
default location within a profile directory (including the other program from
the one running, even though that's technically stored as a custom data
directory).
On Mac/Linux, directories within the data directory are moved with /bin/mv. On
Windows, or if that fails, they're copied recursively using OS.File.move()
(which annoyingly doesn't reliably support directory moving). The former should
be instantaneous on most systems (unless the data directory or 'storage' were
on a different filesystem from $HOME).
If the database fails to transfer, migration fails and the data directory
setting remains on the old directory. If the database transfers but other files
fail, the data directory setting is updated. In both cases, the user is
encouraged to migrate remaining files manually with a button that reveals the
directories and quits the program.
This isn't yet tested on Linux or Windows, and migration isn't yet suggested
automatically.
Adds Zotero.File.reveal(), Zotero.File.directoryIsEmpty(), and
Zotero.File.moveDirectory().
2016-11-12 19:20:34 +00:00
|
|
|
|
2016-11-24 06:19:52 +00:00
|
|
|
stub1.restore();
|
Data directory migration
This adds a new button to the Advanced prefs to migrate the data directory to
$HOME/Zotero. The button only appears if the data directory is set to the
default location within a profile directory (including the other program from
the one running, even though that's technically stored as a custom data
directory).
On Mac/Linux, directories within the data directory are moved with /bin/mv. On
Windows, or if that fails, they're copied recursively using OS.File.move()
(which annoyingly doesn't reliably support directory moving). The former should
be instantaneous on most systems (unless the data directory or 'storage' were
on a different filesystem from $HOME).
If the database fails to transfer, migration fails and the data directory
setting remains on the old directory. If the database transfers but other files
fail, the data directory setting is updated. In both cases, the user is
encouraged to migrate remaining files manually with a button that reveals the
directories and quits the program.
This isn't yet tested on Linux or Windows, and migration isn't yet suggested
automatically.
Adds Zotero.File.reveal(), Zotero.File.directoryIsEmpty(), and
Zotero.File.moveDirectory().
2016-11-12 19:20:34 +00:00
|
|
|
|
|
|
|
yield checkMigration({
|
|
|
|
skipOldDir: true,
|
|
|
|
skipStorageFile1: true,
|
|
|
|
skipNewMarker: true
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.isTrue(yield OS.File.exists(OS.Path.join(oldStorageDir1, storageFile1)));
|
|
|
|
assert.isFalse(yield OS.File.exists(OS.Path.join(oldStorageDir2, storageFile2)));
|
|
|
|
assert.isFalse(yield OS.File.exists(oldTranslatorsDir));
|
|
|
|
assert.isTrue(yield OS.File.exists(newMigrationMarker));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|