Skip to content

Commit b91bd91

Browse files
committed
fix: should be able to rename file to upper or lower case with same name
1 parent 64cc3ef commit b91bd91

File tree

9 files changed

+58
-16
lines changed

9 files changed

+58
-16
lines changed

dist/virtualfs-debug.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19616,6 +19616,7 @@ $b45ac22e865b129b$exports = (parcelRequire("1xCGA"));
1961619616

1961719617
let $e3f139c5065f0041$var$filerLib = null;
1961819618
let $e3f139c5065f0041$var$filerShell = null;
19619+
const $e3f139c5065f0041$var$IS_WINDOWS = navigator.userAgent.includes("Windows");
1961919620
/**
1962019621
* Offers functionality similar to mkdir -p
1962119622
*
@@ -19753,6 +19754,9 @@ const $e3f139c5065f0041$var$fileSystemLib = {
1975319754
cb(new $e3f139c5065f0041$require$Errors.EPERM("Tauri root directory cannot be renamed."));
1975419755
return;
1975519756
}
19757+
if ($e3f139c5065f0041$var$IS_WINDOWS && oldPath.toLowerCase() === newPath.toLowerCase() && $e3f139c5065f0041$require$TauriFS.isTauriSubPath(oldPath) && $e3f139c5065f0041$require$TauriFS.isTauriSubPath(newPath)) // in windows, we should be able to rename "a.txt" to "A.txt". Since windows is case-insensitive,
19758+
// the below stat(A.txt) will return a stat for "a.txt" which is not what we want.
19759+
return $e3f139c5065f0041$require$TauriFS.rename(oldPath, newPath, callbackInterceptor);
1975619760
$e3f139c5065f0041$var$fileSystemLib.stat(newPath, (err)=>{
1975719761
if (!err) {
1975819762
// the destination folder/file exists and we should not rename

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: 7 additions & 6 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.

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@phcode/fs",
33
"description": "Phoenix virtual file system over filer/ browser fs access/ tauri / phoenix web socket APIs",
4-
"version": "3.0.0",
4+
"version": "3.0.1",
55
"keywords": [
66
"phoenix",
77
"browser",

src/fslib.js

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

40+
const IS_WINDOWS = navigator.userAgent.includes('Windows');
4041
/**
4142
* Offers functionality similar to mkdir -p
4243
*
@@ -234,6 +235,12 @@ const fileSystemLib = {
234235
cb(new Errors.EPERM('Tauri root directory cannot be renamed.'));
235236
return;
236237
}
238+
if(IS_WINDOWS && (oldPath.toLowerCase() === newPath.toLowerCase()) &&
239+
TauriFS.isTauriSubPath(oldPath) && TauriFS.isTauriSubPath(newPath)) {
240+
// in windows, we should be able to rename "a.txt" to "A.txt". Since windows is case-insensitive,
241+
// the below stat(A.txt) will return a stat for "a.txt" which is not what we want.
242+
return TauriFS.rename(oldPath, newPath, callbackInterceptor);
243+
}
237244
fileSystemLib.stat(newPath, (err)=>{
238245
if(!err){
239246
// the destination folder/file exists and we should not rename

test/test-dir.browser.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,16 @@ function _setupTests(testType) {
430430
await _validate_exists(`${dirCreated}/b`);
431431
});
432432

433+
it(`Should phoenix ${testType} rename existing lower case dir to upper case dir`, async function () {
434+
let dirCreated = await _writeTestDir();
435+
const dirName = "rename_test_case_sensitive";
436+
const lowerCaseDir = `${dirCreated}/${dirName}`, upperCaseDir = `${dirCreated}/${dirName.toUpperCase()}`;
437+
await _creatDirAndValidate(lowerCaseDir);
438+
await _validateRename(lowerCaseDir, upperCaseDir);
439+
await _validate_not_exists(lowerCaseDir);
440+
await _validate_exists(upperCaseDir);
441+
});
442+
433443
it(`Should phoenix ${testType} rename dir test 2`, async function () {
434444
let dirCreated = await _writeTestDir();
435445
await _creatDirAndValidate(`${dirCreated}/a`);
@@ -441,6 +451,16 @@ function _setupTests(testType) {
441451
await _validate_exists(`${dirCreated}/z/b/x`);
442452
});
443453

454+
it(`Should phoenix ${testType} rename case sensitive dir test 2`, async function () {
455+
let dirCreated = await _writeTestDir();
456+
await _creatDirAndValidate(`${dirCreated}/a`);
457+
await _creatDirAndValidate(`${dirCreated}/a/x`);
458+
await _validateRename(`${dirCreated}/a`, `${dirCreated}/A`);
459+
await _validate_not_exists(`${dirCreated}/a`);
460+
await _validate_exists(`${dirCreated}/A`);
461+
await _validate_exists(`${dirCreated}/A/x`);
462+
});
463+
444464
it(`Should phoenix ${testType} rename non-empty dir`, async function () {
445465
let dirCreated = await _writeTestDir();
446466
await _creatDirAndValidate(`${dirCreated}/a`);

0 commit comments

Comments
 (0)