[英]Rename return “EPERM: operation not permitted” in JavaScript
In my windows server, I found the fs.rename function always return the below error: 在我的Windows服务器中,我发现fs.rename函数总是返回以下错误:
error code is Error: EPERM: operation not permitted, rename 'C:\\javascript\\nodejs\\a.txt' -> 'C:\\javascript\\nodejs\\b.txt'
错误代码是错误:EPERM:不允许操作,重命名'C:\\ javascript \\ nodejs \\ a.txt' - >'C:\\ javascript \\ nodejs \\ b.txt'
The below are the test code: 以下是测试代码:
var fs = require('fs');
fs.writeFileSync('a.txt',"This is a file")
fs.writeFileSync('b.txt',"This is another file")
fs.rename('a.txt','b.txt',function (err) {
console.log("error code is " + err);
});
var text = fs.readFileSync('b.txt', "utf-8");
console.log(text)
However, in the current folder, I do see the original file "a.txt" as well as the new renamed file "b.txt". 但是,在当前文件夹中,我确实看到原始文件“a.txt”以及新重命名的文件“b.txt”。
fs.rename
is just a wrapper to rename
, and according to rename
docs : fs.rename
只是rename
的包装器,并根据rename
文档 :
EPERM or EACCES
The directory containing oldpath has the sticky bit (S_ISVTX)
set and the process's effective user ID is neither the user ID
of the file to be deleted nor that of the directory containing
it, and the process is not privileged (Linux: does not have
the CAP_FOWNER capability); or newpath is an existing file and
the directory containing it has the sticky bit set and the
process's effective user ID is neither the user ID of the file
to be replaced nor that of the directory containing it, and
the process is not privileged (Linux: does not have the
CAP_FOWNER capability); or the filesystem containing pathname
does not support renaming of the type requested.
You probably have no permissions to delete the file or the target file name already exists. 您可能没有权限删除该文件或目标文件名已存在。
After huge struggle found the solution for me .. 👍 经过巨大的斗争为我找到了解决方案..👍
"Create new folders" mkdir E:\\Buildagent\\npm mkdir E:\\Buildagent\\npm-cache “创建新文件夹”mkdir E:\\ Buildagent \\ npm mkdir E:\\ Buildagent \\ npm-cache
"move npm prefix and the cache" robocopy c:\\Users\\the-build-user\\AppData\\Roaming\\npm E:\\Buildagent\\npm robocopy c:\\Users\\the-build-user\\AppData\\Roaming\\npm-cache E:\\Buildagent\\npm-cache /E /MOVE “移动npm前缀和缓存”robocopy c:\\ Users \\ the-build-user \\ AppData \\ Roaming \\ npm E:\\ Buildagent \\ npm robocopy c:\\ Users \\ the-build-user \\ AppData \\ Roaming \\ npm-cache E:\\ Buildagent \\ npm-cache / E / MOVE
"Update the npm config for prefix and cache" npm config set prefix E:\\Buildagent\\npm npm config set cache E:\\Buildagent\\npm-cache “更新npm config for prefix and cache”npm config set prefix E:\\ Buildagent \\ npm npm config set cache E:\\ Buildagent \\ npm-cache
https://alastaircrabtree.com/fixing-intermittant-eperm-operation-not-permitted-on-npm-install/ https://alastaircrabtree.com/fixing-intermittant-eperm-operation-not-permitted-on-npm-install/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.