Skip to content

Commit

Permalink
fix: mac rename fails as mac fs is apparently case insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
abose committed Jun 19, 2024
1 parent 7e2e25d commit 5b75cbc
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 26 deletions.
12 changes: 6 additions & 6 deletions dist/virtualfs-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -17698,8 +17698,9 @@ async function $bd5c47de9e98f4fa$var$rename(oldPath, newPath, cb) {
}, 0);
});
}
// this is when in windows, you have to rename "a.txt" to "A.TXT". We have to have an intermediate name
async function $bd5c47de9e98f4fa$var$renameWindowsSameName(oldPath, newPath, cb) {
// this is when in windows/macos, the fs is not case-sensitive, you have to rename "a.txt" to "A.TXT".
// We have to have an intermediate name
async function $bd5c47de9e98f4fa$var$renameSameNameDiffCase(oldPath, newPath, cb) {
const tempPath = globalObject.path.normalize(oldPath) + "_" + Math.floor(Math.random() * 4294967296);
$bd5c47de9e98f4fa$var$rename(oldPath, tempPath, (err)=>{
if (err) cb(err);
Expand All @@ -17725,7 +17726,7 @@ const $bd5c47de9e98f4fa$var$NativeFS = {
unlink: $bd5c47de9e98f4fa$var$unlink,
copy: $bd5c47de9e98f4fa$var$copy,
rename: $bd5c47de9e98f4fa$var$rename,
renameWindowsSameName: $bd5c47de9e98f4fa$var$renameWindowsSameName
renameSameNameDiffCase: $bd5c47de9e98f4fa$var$renameSameNameDiffCase
};
$bd5c47de9e98f4fa$exports = {
NativeFS: $bd5c47de9e98f4fa$var$NativeFS
Expand Down Expand Up @@ -19627,7 +19628,6 @@ $b45ac22e865b129b$exports = (parcelRequire("1xCGA"));

let $e3f139c5065f0041$var$filerLib = null;
let $e3f139c5065f0041$var$filerShell = null;
const $e3f139c5065f0041$var$IS_WINDOWS = navigator.userAgent.includes("Windows");
/**
* Offers functionality similar to mkdir -p
*
Expand Down Expand Up @@ -19765,11 +19765,11 @@ const $e3f139c5065f0041$var$fileSystemLib = {
cb(new $e3f139c5065f0041$require$Errors.EPERM("Tauri root directory cannot be renamed."));
return;
}
if ($e3f139c5065f0041$var$IS_WINDOWS && oldPath.toLowerCase() === newPath.toLowerCase()) {
if (oldPath !== newPath && oldPath.toLowerCase() === newPath.toLowerCase()) {
// in windows, we should be able to rename "a.txt" to "A.txt". Since windows is case-insensitive,
// the below stat(A.txt) will return a stat for "a.txt" which is not what we want.
if ($e3f139c5065f0041$require$TauriFS.isTauriSubPath(oldPath) && $e3f139c5065f0041$require$TauriFS.isTauriSubPath(newPath)) return $e3f139c5065f0041$require$TauriFS.rename(oldPath, newPath, callbackInterceptor);
else if ($e3f139c5065f0041$require$Mounts.isMountSubPath(oldPath) && $e3f139c5065f0041$require$Mounts.isMountSubPath(newPath)) return $e3f139c5065f0041$require$NativeFS.renameWindowsSameName(oldPath, newPath, callbackInterceptor);
else if ($e3f139c5065f0041$require$Mounts.isMountSubPath(oldPath) && $e3f139c5065f0041$require$Mounts.isMountSubPath(newPath)) return $e3f139c5065f0041$require$NativeFS.renameSameNameDiffCase(oldPath, newPath, callbackInterceptor);
}
$e3f139c5065f0041$var$fileSystemLib.stat(newPath, (err)=>{
if (!err) {
Expand Down
2 changes: 1 addition & 1 deletion dist/virtualfs-debug.js.map

Large diffs are not rendered by default.

19 changes: 10 additions & 9 deletions dist/virtualfs.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/virtualfs.js.map

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions src/fslib.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import * as iconv from 'iconv-lite';
let filerLib = null;
let filerShell = null;

const IS_WINDOWS = navigator.userAgent.includes('Windows');
/**
* Offers functionality similar to mkdir -p
*
Expand Down Expand Up @@ -235,13 +234,13 @@ const fileSystemLib = {
cb(new Errors.EPERM('Tauri root directory cannot be renamed.'));
return;
}
if(IS_WINDOWS && (oldPath.toLowerCase() === newPath.toLowerCase())) {
if(oldPath !== newPath && oldPath.toLowerCase() === newPath.toLowerCase()) {
// in windows, we should be able to rename "a.txt" to "A.txt". Since windows is case-insensitive,
// the below stat(A.txt) will return a stat for "a.txt" which is not what we want.
if(TauriFS.isTauriSubPath(oldPath) && TauriFS.isTauriSubPath(newPath)) {
return TauriFS.rename(oldPath, newPath, callbackInterceptor);
} else if(Mounts.isMountSubPath(oldPath) && Mounts.isMountSubPath(newPath)) {
return NativeFS.renameWindowsSameName(oldPath, newPath, callbackInterceptor);
return NativeFS.renameSameNameDiffCase(oldPath, newPath, callbackInterceptor);
}
}
fileSystemLib.stat(newPath, (err)=>{
Expand Down
7 changes: 4 additions & 3 deletions src/fslib_native.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,9 @@ async function rename(oldPath, newPath, cb) {
});
}

// this is when in windows, you have to rename "a.txt" to "A.TXT". We have to have an intermediate name
async function renameWindowsSameName(oldPath, newPath, cb) {
// this is when in windows/macos, the fs is not case-sensitive, you have to rename "a.txt" to "A.TXT".
// We have to have an intermediate name
async function renameSameNameDiffCase(oldPath, newPath, cb) {
const tempPath = globalObject.path.normalize(oldPath) + "_" + Math.floor(Math.random() * 4294967296);
rename(oldPath, tempPath, (err)=>{
if(err) {
Expand Down Expand Up @@ -443,7 +444,7 @@ const NativeFS = {
unlink,
copy,
rename,
renameWindowsSameName
renameSameNameDiffCase
};

module.exports ={
Expand Down
6 changes: 4 additions & 2 deletions test/test-dir.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

function _setupTests(testType) {
const IS_WINDOWS = navigator.userAgent.includes('Windows');
const IS_MACOS = navigator.userAgent.includes('Macintosh') || navigator.userAgent.includes('Mac OS');

let testPath;

function consoleLogToShell(message) {
Expand Down Expand Up @@ -437,7 +439,7 @@ function _setupTests(testType) {
const lowerCaseDir = `${dirCreated}/${dirName}`, upperCaseDir = `${dirCreated}/${dirName.toUpperCase()}`;
await _creatDirAndValidate(lowerCaseDir);
await _validateRename(lowerCaseDir, upperCaseDir);
if(IS_WINDOWS && (lowerCaseDir.startsWith("/tauri") || lowerCaseDir.startsWith("/mnt/"))) {
if((IS_WINDOWS || IS_MACOS) && (lowerCaseDir.startsWith("/tauri") || lowerCaseDir.startsWith("/mnt/"))) {
await _validate_exists(lowerCaseDir);
} else {
await _validate_not_exists(lowerCaseDir);
Expand All @@ -461,7 +463,7 @@ function _setupTests(testType) {
await _creatDirAndValidate(`${dirCreated}/a`);
await _creatDirAndValidate(`${dirCreated}/a/x`);
await _validateRename(`${dirCreated}/a`, `${dirCreated}/A`);
if(IS_WINDOWS && (dirCreated.startsWith("/tauri") || dirCreated.startsWith("/mnt/"))) {
if((IS_WINDOWS || IS_MACOS) && (dirCreated.startsWith("/tauri") || dirCreated.startsWith("/mnt/"))) {
await _validate_exists(`${dirCreated}/a`);
} else {
await _validate_not_exists(`${dirCreated}/a`);
Expand Down
4 changes: 3 additions & 1 deletion test/test-file.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

function _setupTests(testType) {
const IS_WINDOWS = navigator.userAgent.includes('Windows');
const IS_MACOS = navigator.userAgent.includes('Macintosh') || navigator.userAgent.includes('Mac OS');

let testPath;

function consoleLogToShell(message) {
Expand Down Expand Up @@ -313,7 +315,7 @@ function _setupTests(testType) {
let filePathCreated = await _writeTestFile(fileName);
let newPath = `${testPath}/${fileName.toUpperCase()}`;
await _validateRename(filePathCreated, newPath);
if(IS_WINDOWS && (filePathCreated.startsWith("/tauri") || filePathCreated.startsWith("/mnt/"))) {
if((IS_WINDOWS || IS_MACOS) && (filePathCreated.startsWith("/tauri") || filePathCreated.startsWith("/mnt/"))) {
await _validate_exists(filePathCreated);
} else {
await _validate_not_exists(filePathCreated);
Expand Down

0 comments on commit 5b75cbc

Please sign in to comment.