classification
Title: os.rename(src,dst) does nothing when src and dst files are hard-linked
Type: behavior Stage:
Components: Versions: Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Aaron.Swan, Esa.Peuha, r.david.murray
Priority: normal Keywords:

Created on 2014-06-27 17:54 by Aaron.Swan, last changed 2014-06-30 16:54 by Aaron.Swan.

Messages (5)
msg221699 - (view) Author: Aaron Swan (Aaron.Swan) Date: 2014-06-27 17:54
On Linux Red Hat os.rename(src,dst) does nothing when src and dst files are hard-linked.

It seems like the expected behavior would be the removal of the src file. This would be in keeping with the documentation that states: "On Unix, if dst exists and is a file, it will be replaced silently if the user has permission. "
msg221707 - (view) Author: Esa Peuha (Esa.Peuha) Date: 2014-06-27 18:46
This looks like a documentation bug. Functions in module os are usually just thin wrappers around the underlying OS functions, and POSIX states that doing nothing is the correct thing to do here. (It is arguably a bug in early Unix implementations that got mistakenly codified as part of POSIX, and it is certainly inconsistent with the POSIX requirement that the mv command *must* remove the source file in this case, but there is nothing Python can do about that.)
msg221712 - (view) Author: Aaron Swan (Aaron.Swan) Date: 2014-06-27 19:22
Although using the mv command *does* remove the src file on red hat linux, I can accept that the POSIX requirement that the source *must* be removed might not apply if source is the same as the destination file.

It would be nice if the behavior was consistent, but I think the POSIX requirements are somewhat up for interpretation in this case.

The documentation should probably be updated at the least.
msg221796 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-06-28 15:25
It may be a backward compatibility problem to change it, but although the os functions tend to be thin wrappers, we also try to be cross platform when possible and we tend to follow what the corresponding shell command does rather than what the posix API does when there is a conflict.

Clearly this case is a grey area, but it is worth thinking about at least.  Perhaps the change could be made in the newer and more cross-platform replace.
msg221967 - (view) Author: Aaron Swan (Aaron.Swan) Date: 2014-06-30 16:54
At any rate, it is a bit of a nuisance that files remain present when the intent was to move them.
History
Date User Action Args
2014-06-30 16:54:50Aaron.Swansetmessages: + msg221967
2014-06-28 15:25:43r.david.murraysetnosy: + r.david.murray
messages: + msg221796
2014-06-27 19:22:23Aaron.Swansetmessages: + msg221712
2014-06-27 18:46:05Esa.Peuhasetnosy: + Esa.Peuha
messages: + msg221707
2014-06-27 17:54:35Aaron.Swancreate