Skip to content

Commit 5b75cbc

Browse files
committed
fix: mac rename fails as mac fs is apparently case insensitive
1 parent 7e2e25d commit 5b75cbc

File tree

8 files changed

+31
-26
lines changed

8 files changed

+31
-26
lines changed

dist/virtualfs-debug.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17698,8 +17698,9 @@ async function $bd5c47de9e98f4fa$var$rename(oldPath, newPath, cb) {
1769817698
}, 0);
1769917699
});
1770017700
}
17701-
// this is when in windows, you have to rename "a.txt" to "A.TXT". We have to have an intermediate name
17702-
async function $bd5c47de9e98f4fa$var$renameWindowsSameName(oldPath, newPath, cb) {
17701+
// this is when in windows/macos, the fs is not case-sensitive, you have to rename "a.txt" to "A.TXT".
17702+
// We have to have an intermediate name
17703+
async function $bd5c47de9e98f4fa$var$renameSameNameDiffCase(oldPath, newPath, cb) {
1770317704
const tempPath = globalObject.path.normalize(oldPath) + "_" + Math.floor(Math.random() * 4294967296);
1770417705
$bd5c47de9e98f4fa$var$rename(oldPath, tempPath, (err)=>{
1770517706
if (err) cb(err);
@@ -17725,7 +17726,7 @@ const $bd5c47de9e98f4fa$var$NativeFS = {
1772517726
unlink: $bd5c47de9e98f4fa$var$unlink,
1772617727
copy: $bd5c47de9e98f4fa$var$copy,
1772717728
rename: $bd5c47de9e98f4fa$var$rename,
17728-
renameWindowsSameName: $bd5c47de9e98f4fa$var$renameWindowsSameName
17729+
renameSameNameDiffCase: $bd5c47de9e98f4fa$var$renameSameNameDiffCase
1772917730
};
1773017731
$bd5c47de9e98f4fa$exports = {
1773117732
NativeFS: $bd5c47de9e98f4fa$var$NativeFS
@@ -19627,7 +19628,6 @@ $b45ac22e865b129b$exports = (parcelRequire("1xCGA"));
1962719628

1962819629
let $e3f139c5065f0041$var$filerLib = null;
1962919630
let $e3f139c5065f0041$var$filerShell = null;
19630-
const $e3f139c5065f0041$var$IS_WINDOWS = navigator.userAgent.includes("Windows");
1963119631
/**
1963219632
* Offers functionality similar to mkdir -p
1963319633
*
@@ -19765,11 +19765,11 @@ const $e3f139c5065f0041$var$fileSystemLib = {
1976519765
cb(new $e3f139c5065f0041$require$Errors.EPERM("Tauri root directory cannot be renamed."));
1976619766
return;
1976719767
}
19768-
if ($e3f139c5065f0041$var$IS_WINDOWS && oldPath.toLowerCase() === newPath.toLowerCase()) {
19768+
if (oldPath !== newPath && oldPath.toLowerCase() === newPath.toLowerCase()) {
1976919769
// in windows, we should be able to rename "a.txt" to "A.txt". Since windows is case-insensitive,
1977019770
// the below stat(A.txt) will return a stat for "a.txt" which is not what we want.
1977119771
if ($e3f139c5065f0041$require$TauriFS.isTauriSubPath(oldPath) && $e3f139c5065f0041$require$TauriFS.isTauriSubPath(newPath)) return $e3f139c5065f0041$require$TauriFS.rename(oldPath, newPath, callbackInterceptor);
19772-
else if ($e3f139c5065f0041$require$Mounts.isMountSubPath(oldPath) && $e3f139c5065f0041$require$Mounts.isMountSubPath(newPath)) return $e3f139c5065f0041$require$NativeFS.renameWindowsSameName(oldPath, newPath, callbackInterceptor);
19772+
else if ($e3f139c5065f0041$require$Mounts.isMountSubPath(oldPath) && $e3f139c5065f0041$require$Mounts.isMountSubPath(newPath)) return $e3f139c5065f0041$require$NativeFS.renameSameNameDiffCase(oldPath, newPath, callbackInterceptor);
1977319773
}
1977419774
$e3f139c5065f0041$var$fileSystemLib.stat(newPath, (err)=>{
1977519775
if (!err) {

dist/virtualfs-debug.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/virtualfs.js

Lines changed: 10 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/virtualfs.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/fslib.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import * as iconv from 'iconv-lite';
3737
let filerLib = null;
3838
let filerShell = null;
3939

40-
const IS_WINDOWS = navigator.userAgent.includes('Windows');
4140
/**
4241
* Offers functionality similar to mkdir -p
4342
*
@@ -235,13 +234,13 @@ const fileSystemLib = {
235234
cb(new Errors.EPERM('Tauri root directory cannot be renamed.'));
236235
return;
237236
}
238-
if(IS_WINDOWS && (oldPath.toLowerCase() === newPath.toLowerCase())) {
237+
if(oldPath !== newPath && oldPath.toLowerCase() === newPath.toLowerCase()) {
239238
// in windows, we should be able to rename "a.txt" to "A.txt". Since windows is case-insensitive,
240239
// the below stat(A.txt) will return a stat for "a.txt" which is not what we want.
241240
if(TauriFS.isTauriSubPath(oldPath) && TauriFS.isTauriSubPath(newPath)) {
242241
return TauriFS.rename(oldPath, newPath, callbackInterceptor);
243242
} else if(Mounts.isMountSubPath(oldPath) && Mounts.isMountSubPath(newPath)) {
244-
return NativeFS.renameWindowsSameName(oldPath, newPath, callbackInterceptor);
243+
return NativeFS.renameSameNameDiffCase(oldPath, newPath, callbackInterceptor);
245244
}
246245
}
247246
fileSystemLib.stat(newPath, (err)=>{

src/fslib_native.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,9 @@ async function rename(oldPath, newPath, cb) {
410410
});
411411
}
412412

413-
// this is when in windows, you have to rename "a.txt" to "A.TXT". We have to have an intermediate name
414-
async function renameWindowsSameName(oldPath, newPath, cb) {
413+
// this is when in windows/macos, the fs is not case-sensitive, you have to rename "a.txt" to "A.TXT".
414+
// We have to have an intermediate name
415+
async function renameSameNameDiffCase(oldPath, newPath, cb) {
415416
const tempPath = globalObject.path.normalize(oldPath) + "_" + Math.floor(Math.random() * 4294967296);
416417
rename(oldPath, tempPath, (err)=>{
417418
if(err) {
@@ -443,7 +444,7 @@ const NativeFS = {
443444
unlink,
444445
copy,
445446
rename,
446-
renameWindowsSameName
447+
renameSameNameDiffCase
447448
};
448449

449450
module.exports ={

test/test-dir.browser.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
function _setupTests(testType) {
44
const IS_WINDOWS = navigator.userAgent.includes('Windows');
5+
const IS_MACOS = navigator.userAgent.includes('Macintosh') || navigator.userAgent.includes('Mac OS');
6+
57
let testPath;
68

79
function consoleLogToShell(message) {
@@ -437,7 +439,7 @@ function _setupTests(testType) {
437439
const lowerCaseDir = `${dirCreated}/${dirName}`, upperCaseDir = `${dirCreated}/${dirName.toUpperCase()}`;
438440
await _creatDirAndValidate(lowerCaseDir);
439441
await _validateRename(lowerCaseDir, upperCaseDir);
440-
if(IS_WINDOWS && (lowerCaseDir.startsWith("/tauri") || lowerCaseDir.startsWith("/mnt/"))) {
442+
if((IS_WINDOWS || IS_MACOS) && (lowerCaseDir.startsWith("/tauri") || lowerCaseDir.startsWith("/mnt/"))) {
441443
await _validate_exists(lowerCaseDir);
442444
} else {
443445
await _validate_not_exists(lowerCaseDir);
@@ -461,7 +463,7 @@ function _setupTests(testType) {
461463
await _creatDirAndValidate(`${dirCreated}/a`);
462464
await _creatDirAndValidate(`${dirCreated}/a/x`);
463465
await _validateRename(`${dirCreated}/a`, `${dirCreated}/A`);
464-
if(IS_WINDOWS && (dirCreated.startsWith("/tauri") || dirCreated.startsWith("/mnt/"))) {
466+
if((IS_WINDOWS || IS_MACOS) && (dirCreated.startsWith("/tauri") || dirCreated.startsWith("/mnt/"))) {
465467
await _validate_exists(`${dirCreated}/a`);
466468
} else {
467469
await _validate_not_exists(`${dirCreated}/a`);

test/test-file.browser.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
function _setupTests(testType) {
44
const IS_WINDOWS = navigator.userAgent.includes('Windows');
5+
const IS_MACOS = navigator.userAgent.includes('Macintosh') || navigator.userAgent.includes('Mac OS');
6+
57
let testPath;
68

79
function consoleLogToShell(message) {
@@ -313,7 +315,7 @@ function _setupTests(testType) {
313315
let filePathCreated = await _writeTestFile(fileName);
314316
let newPath = `${testPath}/${fileName.toUpperCase()}`;
315317
await _validateRename(filePathCreated, newPath);
316-
if(IS_WINDOWS && (filePathCreated.startsWith("/tauri") || filePathCreated.startsWith("/mnt/"))) {
318+
if((IS_WINDOWS || IS_MACOS) && (filePathCreated.startsWith("/tauri") || filePathCreated.startsWith("/mnt/"))) {
317319
await _validate_exists(filePathCreated);
318320
} else {
319321
await _validate_not_exists(filePathCreated);

0 commit comments

Comments
 (0)