Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
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

Closed

Description

@fishbar

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

os: windows | linux ubuntu
node:v0.6.8

Activity

  1. Mithgol commented on Feb 6, 2012

    @Mithgol

    The same happens in Node.js v0.6.10, see the screenshot:

    the screenshot

  2. TooTallNate commented on Feb 6, 2012

    @TooTallNate

    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.

  3. added a commit that references this issue on Feb 6, 2012
  4. chjj commented on Feb 6, 2012

    @chjj

    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.

  5. Mithgol commented on Feb 6, 2012

    @Mithgol

    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).

  6. chjj commented on Feb 6, 2012

    @chjj

    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.

    Node is supposed to be low level.

  7. indutny commented on Feb 6, 2012

    @indutny
    Member

    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.

  8. Mithgol commented on Feb 6, 2012

    @Mithgol

    Note to future self: node-fs-extra has its implementation of rm -rf and a file copier (but the latter is not recursive). Has five dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions