refactor filesystem.js to use isWindowsOS()

This commit is contained in:
Pragadesh-45 2024-10-01 14:57:19 +05:30
parent 95e56cd9c9
commit de2053f988

View File

@ -160,6 +160,10 @@ const sanitizeDirectoryName = (name) => {
return name.replace(/[<>:"/\\|?*\x00-\x1F]+/g, '-');
};
const isWindowsOS = () => {
return os.platform() === 'win32';
}
const safeToRename = (oldPath, newPath) => {
try {
// If the new path doesn't exist, it's safe to rename
@ -170,7 +174,7 @@ const safeToRename = (oldPath, newPath) => {
const oldStat = fs.statSync(oldPath);
const newStat = fs.statSync(newPath);
if (os.platform() === 'win32') {
if (isWindowsOS()) {
// Windows-specific comparison:
// Check if both files have the same birth time, size (Since, Win FAT-32 doesn't use inodes)
@ -204,5 +208,6 @@ module.exports = {
searchForFiles,
searchForBruFiles,
sanitizeDirectoryName,
isWindowsOS,
safeToRename
};