Skip to content

Commit 28a569b

Browse files
committed
chore: support case insensitive rename a.txt to A.TXT in win /mnt points and win test fixes
1 parent b91bd91 commit 28a569b

File tree

8 files changed

+112
-62
lines changed

8 files changed

+112
-62
lines changed

dist/virtualfs-debug.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17698,6 +17698,16 @@ 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) {
17703+
const tempPath = globalObject.path.normalize(oldPath) + "_" + Math.floor(Math.random() * 4294967296);
17704+
$bd5c47de9e98f4fa$var$rename(oldPath, tempPath, (err)=>{
17705+
if (err) cb(err);
17706+
else setTimeout(()=>{
17707+
$bd5c47de9e98f4fa$var$rename(tempPath, newPath, cb);
17708+
}, 0);
17709+
});
17710+
}
1770117711
function $bd5c47de9e98f4fa$var$mountNativeFolder(...args) {
1770217712
$bd5c47de9e98f4fa$require$Mounts.mountNativeFolder(...args);
1770317713
}
@@ -17714,7 +17724,8 @@ const $bd5c47de9e98f4fa$var$NativeFS = {
1771417724
writeFile: $bd5c47de9e98f4fa$var$writeFile,
1771517725
unlink: $bd5c47de9e98f4fa$var$unlink,
1771617726
copy: $bd5c47de9e98f4fa$var$copy,
17717-
rename: $bd5c47de9e98f4fa$var$rename
17727+
rename: $bd5c47de9e98f4fa$var$rename,
17728+
renameWindowsSameName: $bd5c47de9e98f4fa$var$renameWindowsSameName
1771817729
};
1771917730
$bd5c47de9e98f4fa$exports = {
1772017731
NativeFS: $bd5c47de9e98f4fa$var$NativeFS
@@ -19754,9 +19765,12 @@ const $e3f139c5065f0041$var$fileSystemLib = {
1975419765
cb(new $e3f139c5065f0041$require$Errors.EPERM("Tauri root directory cannot be renamed."));
1975519766
return;
1975619767
}
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);
19768+
if ($e3f139c5065f0041$var$IS_WINDOWS && oldPath.toLowerCase() === newPath.toLowerCase()) {
19769+
// in windows, we should be able to rename "a.txt" to "A.txt". Since windows is case-insensitive,
19770+
// the below stat(A.txt) will return a stat for "a.txt" which is not what we want.
19771+
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);
19773+
}
1976019774
$e3f139c5065f0041$var$fileSystemLib.stat(newPath, (err)=>{
1976119775
if (!err) {
1976219776
// 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: 51 additions & 49 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: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,14 @@ const fileSystemLib = {
235235
cb(new Errors.EPERM('Tauri root directory cannot be renamed.'));
236236
return;
237237
}
238-
if(IS_WINDOWS && (oldPath.toLowerCase() === newPath.toLowerCase()) &&
239-
TauriFS.isTauriSubPath(oldPath) && TauriFS.isTauriSubPath(newPath)) {
238+
if(IS_WINDOWS && (oldPath.toLowerCase() === newPath.toLowerCase())) {
240239
// in windows, we should be able to rename "a.txt" to "A.txt". Since windows is case-insensitive,
241240
// 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);
241+
if(TauriFS.isTauriSubPath(oldPath) && TauriFS.isTauriSubPath(newPath)) {
242+
return TauriFS.rename(oldPath, newPath, callbackInterceptor);
243+
} else if(Mounts.isMountSubPath(oldPath) && Mounts.isMountSubPath(newPath)) {
244+
return NativeFS.renameWindowsSameName(oldPath, newPath, callbackInterceptor);
245+
}
243246
}
244247
fileSystemLib.stat(newPath, (err)=>{
245248
if(!err){

src/fslib_native.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,20 @@ 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) {
415+
const tempPath = globalObject.path.normalize(oldPath) + "_" + Math.floor(Math.random() * 4294967296);
416+
rename(oldPath, tempPath, (err)=>{
417+
if(err) {
418+
cb(err);
419+
} else {
420+
setTimeout(()=>{
421+
rename(tempPath, newPath, cb);
422+
}, 0);
423+
}
424+
});
425+
}
426+
413427
function mountNativeFolder(...args) {
414428
Mounts.mountNativeFolder(...args);
415429
}
@@ -428,7 +442,8 @@ const NativeFS = {
428442
writeFile,
429443
unlink,
430444
copy,
431-
rename
445+
rename,
446+
renameWindowsSameName
432447
};
433448

434449
module.exports ={

test/test-dir.browser.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* global expect , Filer, fs, waitForTrue, TEST_TYPE_FS_ACCESS, TEST_TYPE_FILER, TEST_TYPE_TAURI, TEST_TYPE_TAURI_WS, path, iconv*/
22

3+
const IS_WINDOWS = navigator.userAgent.includes('Windows');
4+
35
function _setupTests(testType) {
46
let testPath;
57

@@ -436,7 +438,11 @@ function _setupTests(testType) {
436438
const lowerCaseDir = `${dirCreated}/${dirName}`, upperCaseDir = `${dirCreated}/${dirName.toUpperCase()}`;
437439
await _creatDirAndValidate(lowerCaseDir);
438440
await _validateRename(lowerCaseDir, upperCaseDir);
439-
await _validate_not_exists(lowerCaseDir);
441+
if(IS_WINDOWS && (lowerCaseDir.startsWith("/tauri") || lowerCaseDir.startsWith("/mnt/"))) {
442+
await _validate_exists(lowerCaseDir);
443+
} else {
444+
await _validate_not_exists(lowerCaseDir);
445+
}
440446
await _validate_exists(upperCaseDir);
441447
});
442448

@@ -456,7 +462,11 @@ function _setupTests(testType) {
456462
await _creatDirAndValidate(`${dirCreated}/a`);
457463
await _creatDirAndValidate(`${dirCreated}/a/x`);
458464
await _validateRename(`${dirCreated}/a`, `${dirCreated}/A`);
459-
await _validate_not_exists(`${dirCreated}/a`);
465+
if(IS_WINDOWS && (dirCreated.startsWith("/tauri") || dirCreated.startsWith("/mnt/"))) {
466+
await _validate_exists(`${dirCreated}/a`);
467+
} else {
468+
await _validate_not_exists(`${dirCreated}/a`);
469+
}
460470
await _validate_exists(`${dirCreated}/A`);
461471
await _validate_exists(`${dirCreated}/A/x`);
462472
});

test/test-file.browser.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* global expect , Filer, fs, TEST_TYPE_FS_ACCESS, TEST_TYPE_FILER, TEST_TYPE_TAURI, TEST_TYPE_TAURI_WS*/
22

3+
const IS_WINDOWS = navigator.userAgent.includes('Windows');
4+
35
function _setupTests(testType) {
46
let testPath;
57

@@ -312,7 +314,11 @@ function _setupTests(testType) {
312314
let filePathCreated = await _writeTestFile(fileName);
313315
let newPath = `${testPath}/${fileName.toUpperCase()}`;
314316
await _validateRename(filePathCreated, newPath);
315-
await _validate_not_exists(filePathCreated);
317+
if(IS_WINDOWS && (filePathCreated.startsWith("/tauri") || filePathCreated.startsWith("/mnt/"))) {
318+
await _validate_exists(filePathCreated);
319+
} else {
320+
await _validate_not_exists(filePathCreated);
321+
}
316322
await _validate_exists(newPath);
317323
});
318324

0 commit comments

Comments
 (0)