[issue21876] os.rename(src, dst) does nothing when src and dst files are hard-linked

2021-11-17 Thread Eryk Sun


Eryk Sun  added the comment:

> It's nice if os.rename() can be atomic. 

How about fixing the behavior in shutil.move()? Currently it tries 
os.rename(src, dst) without checking for this case. For example:

>>> os.path.samefile('src', 'dst')
True
>>> shutil.move('src', 'dst')
'dst'
>>> os.path.exists('src')
True
>>> os.stat('src').st_nlink
2

---

Note that there's nothing to fix, and not much to document in Windows. It works 
as expected. A slight difference from the general case is that os.replace() is 
required only when replacing a different file, not a hard link for the same 
file.

--
nosy: +eryksun

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21876] os.rename(src, dst) does nothing when src and dst files are hard-linked

2021-11-17 Thread STINNER Victor


STINNER Victor  added the comment:

It's nice if os.rename() can be atomic. It can be atomic if it is implemented 
as a single syscall and the source and the destination are on the same 
filesystem.

If we modify the implement to check if src and/or dst is a hardlink, we will 
need more syscalls which cannot be atomic. What if another process replaces src 
or dst before or after the rename() syscall?

I suggest to document the issue. Or maybe we need a new flavor which keeps the 
current behavior.

"Atomic write" is an old topic and no one managed to implement it in a portable 
way. So maybe you can ignore the atomicity constraint.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21876] os.rename(src, dst) does nothing when src and dst files are hard-linked

2021-10-25 Thread Irit Katriel


Change by Irit Katriel :


--
nosy: +vstinner

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21876] os.rename(src, dst) does nothing when src and dst files are hard-linked

2014-06-30 Thread Aaron Swan

Aaron Swan added the comment:

At any rate, it is a bit of a nuisance that files remain present when the 
intent was to move them.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21876
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21876] os.rename(src, dst) does nothing when src and dst files are hard-linked

2014-06-28 Thread R. David Murray

R. David Murray added the comment:

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.

--
nosy: +r.david.murray

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21876
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21876] os.rename(src, dst) does nothing when src and dst files are hard-linked

2014-06-27 Thread Aaron Swan

New submission from Aaron Swan:

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. 

--
messages: 221699
nosy: Aaron.Swan
priority: normal
severity: normal
status: open
title: os.rename(src,dst) does nothing when src and dst files are hard-linked
type: behavior
versions: Python 2.7

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21876
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21876] os.rename(src, dst) does nothing when src and dst files are hard-linked

2014-06-27 Thread Esa Peuha

Esa Peuha added the comment:

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.)

--
nosy: +Esa.Peuha

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21876
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21876] os.rename(src, dst) does nothing when src and dst files are hard-linked

2014-06-27 Thread Aaron Swan

Aaron Swan added the comment:

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.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21876
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com