fabiospampinato / atomically

Read and write files atomically and reliably.
MIT License
160 stars 9 forks source link

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

Open ci010 opened 8 months ago

ci010 commented 8 months ago

I use this library to safe user json config file.

The full error is like:

EXDEV: cross-device link not permitted, rename 'C:\Users\\AppData\Roaming\xmcl\user.json.tmp-48051806880cfebe' -> 'C:\Users\\AppData\Roaming\xmcl\user.json'

I only observe this issue in telemetry. I cannot repro this in my environment.

Any idea about this issue?

I'm using atomically 2.0.1. Currently the users encountered this issue are using Windows.

fabiospampinato commented 5 months ago

I think this error is about renaming across different volumes, which in general is not an atomic operation so the OS says it can't do it, or at least that's how I understood it.

In the sanitized paths you provided I'm assuming the <username> and <user> placeholders are supposed to be the same string, right? If so then it seems weird that this error is thrown when renaming a file within the same folder, which I don't see how it could trigger that error. Maybe the user.json file is a symlink or something? I've no idea on how to reproduce this issue 🤔 And either way I'm not sure there are alternative strategies that could be used, we just need the rename to work for the write to be actually atomic.

Potentially what you could do is catching that error and falling back to regular writing, but obviously that's not great if you want your writes to not corrupt the file.

ci010 commented 5 months ago

I think this error is about renaming across different volumes, which in general is not an atomic operation so the OS says it can't do it, or at least that's how I understood it.

In the sanitized paths you provided I'm assuming the <username> and <user> placeholders are supposed to be the same string, right? If so then it seems weird that this error is thrown when renaming a file within the same folder, which I don't see how it could trigger that error. Maybe the user.json file is a symlink or something? I've no idea on how to reproduce this issue 🤔 And either way I'm not sure there are alternative strategies that could be used, we just need the rename to work for the write to be actually atomic.

Potentially what you could do is catching that error and falling back to regular writing, but obviously that's not great if you want your writes to not corrupt the file.

Yes, the error should represent the cross volumes error, but I'm pretty sure both files are on the same folder. Currently I try to fallback to directly write the file back as workaround and it works okay.