< :前の番号
^ :番号順リスト
> :次の番号
P :前の記事(スレッド移動)
N :次の記事(スレッド移動)
|<:前のスレッド
>|:次のスレッド
^ :返事先
_:自分への返事
>:同じ返事先を持つ記事(前)
<:同じ返事先を持つ記事(後)
---:分割してスレッド表示、再表示
| :分割して(縦)スレッド表示、再表示
~ :スレッドのフレーム消去
.:インデックス
..:インデックスのインデックス
Issue #13696 has been updated by duerst (Martin Drst).
nobu (Nobuyoshi Nakada) wrote:
> Glass_saga (Masaki Matsushita) wrote:
> > ```ruby
> > File.rename("hoge", "fuga", exchange: true) # atomically exchanged
> > ```
>
> How about another method, say, `File.exchange`?
>
> > ```ruby
> > File.rename("hoge", "fuga", noreplace: true) #=> File exists @ syserr_fail2_in - fuga (Errno::EEXIST)
> > ```
>
> 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.
----------------------------------------
Feature #13696: Add exchange and noreplace options to File.rename
https://bugs.ruby-lang.org/issues/13696#change-66889
* Author: Glass_saga (Masaki Matsushita)
* Status: Open
* Priority: Normal
* Assignee: Glass_saga (Masaki Matsushita)
* Target version: 2.5
----------------------------------------
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:
```ruby
File.write("hoge", "hoge")
File.write("fuga", "fuga")
File.rename("hoge", "fuga", exchange: true) # atomically exchanged
File.read("fuga") #=> "hoge"
File.rename("hoge", "fuga", noreplace: true) #=> File exists @ syserr_fail2_in - fuga (Errno::EEXIST)
```
---Files--------------------------------
patch.diff (4.19 KB)
patch.diff (4.84 KB)
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>