Fix 'false' filename after case-only rename on Macs

Zotero.File.move() now forces `overwrite` if the old and new filenames
differ only by case, since otherwise on a case-insensitive filesystem
OS.File.move() does an existence check and thinks that the target file
exists.
This commit is contained in:
Dan Stillman 2020-04-22 00:01:28 -04:00
parent 595ba396ef
commit 81e2bee452
3 changed files with 35 additions and 2 deletions

View file

@ -132,6 +132,17 @@ describe("Zotero.File", function () {
assert.isTrue(await OS.File.exists(destFile));
});
// Only relevant on a case-insensitive filesystem
it("should rename a file with a case-only change (Mac)", async function () {
var tmpDir = await getTempDirectory();
var sourceFile = OS.Path.join(tmpDir, 'a');
var destFile = OS.Path.join(tmpDir, 'A');
await Zotero.File.putContentsAsync(sourceFile, 'foo');
var newFilename = await Zotero.File.rename(sourceFile, 'A');
assert.equal(newFilename, 'A');
assert.equal(await Zotero.File.getContentsAsync(destFile), 'foo');
});
it("should overwrite an existing file if `overwrite` is true", async function () {
var tmpDir = await getTempDirectory();
var sourceFile = OS.Path.join(tmpDir, 'a');