Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EXDEV: cross-device link not permitted, rename #106

Closed
mifi opened this issue Apr 4, 2020 · 6 comments
Closed

EXDEV: cross-device link not permitted, rename #106

mifi opened this issue Apr 4, 2020 · 6 comments

Comments

@mifi
Copy link

mifi commented Apr 4, 2020

A user of my electron app is getting this error on Windows:

78456447-004d4700-76a4-11ea-83fc-3d13ab5d6cb7

See mifi/lossless-cut#292

It is renaming from one drive to the same drive, so I'm not sure why it's giving this error, but it could be some virtual drive stuff going on on windows, especially when running as an appx from Windows Store.

I found that npm had the same issue before:
npm/npm#13306 (comment)

...also not really cross-device moving, but it crashes still.

It seems like node-fs-extra already has built-in support for handling this case:

I see that in Conf, which electron-store is using, you are using write-file-atomic, which is the one that is throwing EXDEV. Maybe better to switch to the more robust fs-extra, or at least catch EXDEV and then instead copy/delete the file? What do you think?

mifi added a commit to mifi/conf that referenced this issue Apr 5, 2020
@mifi
Copy link
Author

mifi commented Apr 5, 2020

I fake reproduced this error by modifying my lossless-cut/node_modules/write-file-atomic/index.js and adding:

...
    if (options.chown) fs.chownSync(tmpfile, options.chown.uid, options.chown.gid)
    if (options.mode) fs.chmodSync(tmpfile, options.mode)


    const testErr = new Error("EXDEV: cross-device link not permitted, rename '...' -> '....'");
    testErr.errno = -18;
    testErr.syscall = 'rename';
    testErr.code = 'EXDEV';
    testErr.path = '/Users/mifi/test.txt';
    testErr.dest = '/Volumes/USB/test.txt';
    throw testErr;


    fs.renameSync(tmpfile, filename)
    threw = false
...

@mifi
Copy link
Author

mifi commented Apr 5, 2020

I have created a PR, and tested that it works with my fake reproduced error.

@mifi
Copy link
Author

mifi commented Apr 5, 2020

We could have added workaround in write-file-atomic instead, but I feel that it will violate the purpose of that package, because the write can no longer be atomic when this error occurs.

@sindresorhus
Copy link
Owner

https://github.com/sindresorhus/conf/releases/tag/v6.2.3

Just reinstall electron-store to get it.

@sindresorhus
Copy link
Owner

This sounds more like a Node.js bug to me. EXDEV should not be thrown when they're in the same directory, AFAIK.

@mifi
Copy link
Author

mifi commented Apr 5, 2020

I feel more like it’s an OS bug or limitation in Windows 10. Im pretty sure the low level api call rename is giving this error to nodejs. since rename is specified to be atomic, then it has to throw because doing anything else would break its atomicity guarantee. It kind of sucks because it’s a special case that any developer who uses rename (or write-file-atomic) needs to handle. And it is very obscure and hard to reproduce.

Node.js fs.rename uses libuv uv_fs_rename which says "Equivalent to rename(2)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants