Feature #13696
openAdd exchange and noreplace options to File.rename
Description
renameat2(2) introduced in linux kernel 3.15 takes following flags.
RENAME_EXCHANGE: Atomically exchange oldpath and newpath.
RENAME_NOREPLACE: Don't overwrite newpath of the rename. Return an error if newpath already exists.
This change makes File.rename take these flags as keyword arguments.
Example:
Files
Updated by nobu (Nobuyoshi Nakada) about 9 years ago
- Description updated (diff)
Glass_saga (Masaki Matsushita) wrote:
How about another method, say, File.exchange?
I prefer positive-form to negative-form as an option, i.e., File.rename(old, new[, replace: true]).
Updated by shevegen (Robert A. Heiler) about 9 years ago
I prefer positive-form to negative-form as an option
I do too. I found it in general easier (for me) to understand positive/forward
declarations.
Updated by Glass_saga (Masaki Matsushita) about 9 years ago
- File patch.diff patch.diff added
Thank you for your comments.
I implemented FIle.exchange and made the noreplace flag in positive-form.
Updated by nobu (Nobuyoshi Nakada) about 9 years ago
Is "atomically" important?
If no, it'd be possible to implement without kernel support.
Updated by normalperson (Eric Wong) about 9 years ago
nobu@ruby-lang.org wrote:
Is "atomically" important?
If no, it'd be possible to implement without kernel support.
Yes, atomicity is an important distinction.
We should not try to implement this non-atomically without kernel
support; it will quietly break code which expects the atomicity.
I am recalling similar problems around posix_fallocate in glibc:
https://sourceware.org/bugzilla/show_bug.cgi?id=15661
Updated by Glass_saga (Masaki Matsushita) almost 9 years ago
Updated by duerst (Martin Dürst) almost 9 years ago
nobu (Nobuyoshi Nakada) wrote:
Glass_saga (Masaki Matsushita) wrote:
How about another method, say,
File.exchange?I prefer positive-form to negative-form as an option, i.e.,
File.rename(old, new[, replace: true]).
I think both exchange: and noreplace: are difficult to understand for an outside user. I think overwrite: is much easier to understand.
Updated by shyouhei (Shyouhei Urabe) almost 9 years ago
I think it's hard to have platform-specific API extensions like this to be in-core. If atomicity is such an important feature (and I'm sure it is), it's hard to emulate this in pure-userland for people without OS that support it.
This should be implemented as a gem. That way, gem install can bail out purposefully for unsupported platforms. That should prevent hidden race condition that you want to avoid.
Updated by naruse (Yui NARUSE) over 8 years ago
- Target version deleted (
2.5)
Updated by hsbt (Hiroshi SHIBATA) over 2 years ago
- Status changed from Open to Assigned