I am trying to write a server in node.js that will work like a simplified google drive / onedrive. I wrote a method for renaming files/directories, but it doesn't work in all cases. Here is the code below:
try {
if (!fs.existsSync(fullPath)) {
reject(new Error('The file to be renamed does not exist!'));
} else if (fs.existsSync(newPath)) {
reject(new Error('A file already exists with that name!'));
} else {
fs.renameSync(fullPath, newPath);
resolve(newPath);
}
} catch (err) {
reject(err);
}
It has no problem renaming files, or renaming directories that contain no subdirectories. But when a directory has one or more subdirectories, the renaming fails.
I am using a windows platform, and I get the following error. I have tried changing file permissions before renaming with fs.chmodSync(fullPath, 0o777), but the error still persists.
"errno": -4048,
"syscall": "rename",
"code": "EPERM",
I thought the problem was with windows and it's filesystem usage, so I tried running the whole thing inside a Docker container (the final product will be deployed on docker), but then I got the following error:
"errno": -18,
"syscall": "rename",
"code": "EXDEV",
The problem is that my paths are normalized and there is nothing like copying from one drive to another, if I console.log my fullPath and newPath, I get something like:
src/test-storage/myFolder/aFolder
src/test-storage/myFolder/xFolder
Thank you in advance for any help. Have a nice day! :)