Project

General

Profile

Actions

Feature #13696

open

Add exchange and noreplace options to File.rename

Added by Glass_saga (Masaki Matsushita) about 4 years ago. Updated over 3 years ago.

Status:
Open
Priority:
Normal
Target version:
-
[ruby-core:81823]

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:

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 Glass_saga (Masaki Matsushita), 06/29/2017 02:06 AM
patch.diff (4.84 KB) patch.diff Glass_saga (Masaki Matsushita), 06/30/2017 03:42 AM
Actions

Also available in: Atom PDF