You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
fs.rename() can't move file between two different disks #2703
when upload file using formiddle module ,as default posted file will be written to a tmp dir(/tmp/xxxxx.file) . in my response handler, i want move this tmp file to apps storage path using fs.rename() . but fs.rename() always throw exception(can not find the source file: /tmp/xxxx.file) .
so i changed the formiddle module's default tmp folder into same disk with apps ,now it's works well
Someone correct me if I'm wrong, by I believe that's Just How It Works™. Since the fs module is almost 1-1 matchups to their C counterparts, that's just how the low-level rename(2) function works. For example, the high-level mv command first tries rename(2), then falls back on creating a copy of the original to the target then deleting the original if that fails. So you'll have to write a higher level cp() function or something that does just that.
The UNKNOWN error is a bug though, that should be EXDEV.
Someone correct me if I'm wrong, by I believe that's Just How It Works™.
This. I don't know if there is an OS that would let you rename across filesystems. You have to copy the data and delete the old file. Rename just changes the link, it can't actually move data from one place to another.
PHP's rename() can rename across Unix partitions (since PHP 4.3.3) and across Windows drives (since PHP 5.3.1), and I guess that is why some people will inevitably try using Node's function in similar ways.
If we no one is going to extend fs.rename() and fs.renameSync(), then there should be some fs.mv() and fs.mvSync() to act like the high-level mv (and even, most likely, to be used instead of their rename counterparts in most cases: it's easier then making the JavaScript guess about drives and partitions).
I disagree. If you're adding a mv that's going to work no matter what, and can recursively move files across file systems if need be (and it would have to be recursive to match behavior of rename()'ing a directory), you're up to you ears in code. You're essentially writing an implementation of cp -r and a rm -rf as well. On top of that, you have to write a sync and an async version of each.
Activity
Mithgol commentedon Feb 6, 2012
The same happens in Node.js v0.6.10, see the screenshot:
TooTallNate commentedon Feb 6, 2012
Someone correct me if I'm wrong, by I believe that's Just How It Works™. Since the
fsmodule is almost 1-1 matchups to their C counterparts, that's just how the low-levelrename(2)function works. For example, the high-levelmvcommand first triesrename(2), then falls back on creating a copy of the original to the target then deleting the original if that fails. So you'll have to write a higher levelcp()function or something that does just that.The
UNKNOWNerror is a bug though, that should beEXDEV.Add EXDEV to the errno map.
chjj commentedon Feb 6, 2012
This. I don't know if there is an OS that would let you rename across filesystems. You have to copy the data and delete the old file. Rename just changes the link, it can't actually move data from one place to another.
Mithgol commentedon Feb 6, 2012
PHP's
rename()can rename across Unix partitions (since PHP 4.3.3) and across Windows drives (since PHP 5.3.1), and I guess that is why some people will inevitably try using Node's function in similar ways.If we no one is going to extend
fs.rename()andfs.renameSync(), then there should be somefs.mv()andfs.mvSync()to act like the high-levelmv(and even, most likely, to be used instead of theirrenamecounterparts in most cases: it's easier then making the JavaScript guess about drives and partitions).chjj commentedon Feb 6, 2012
I disagree. If you're adding a
mvthat's going to work no matter what, and can recursively move files across file systems if need be (and it would have to be recursive to match behavior of rename()'ing a directory), you're up to you ears in code. You're essentially writing an implementation ofcp -rand arm -rfas well. On top of that, you have to write a sync and an async version of each.Node is supposed to be low level.
indutny commentedon Feb 6, 2012
Fully agreed with the @chjj and @TooTallNate point.
rename()is a atomic and low-level.High-level implementation may be done ( and probably is already done) in user-land modules and should not go into the core.
Mithgol commentedon Feb 6, 2012
Note to future self: node-fs-extra has its implementation of
rm -rfand a file copier (but the latter is not recursive). Has five dependencies.Add fs-extra for move function, this is demanding if you want to use …