[New-bugs-announce] [issue46763] os.path.samefile incorrect results for shadow copies

Nick Venenga report at bugs.python.org
Tue Feb 15 20:45:13 EST 2022


New submission from Nick Venenga <nick at venenga.com>:

shutil.copy fails to copy a file from a shadow copy back to its original file since os.path.samefile returns True. os.path.samefile doesn't reliably detect these files are different since it relies on ino which is the same for both files

>>> sc = pathlib.Path('//?/GLOBALROOT/Device/HarddiskVolumeShadowCopy3/test.file')
>>> o = pathlib.Path("V:/test.file")
>>> os.path.samefile(sc, o)
True
>>> os.stat(sc)
os.stat_result(st_mode=33206, st_ino=3458764513820579328, st_dev=1792739134, st_nlink=1, st_uid=0, st_gid=0, st_size=1, st_atime=1644973968, st_mtime=1644974052, st_ctime=1644973968)
>>> os.stat(o)
os.stat_result(st_mode=33206, st_ino=3458764513820579328, st_dev=1792739134, st_nlink=1, st_uid=0, st_gid=0, st_size=2, st_atime=1644973968, st_mtime=1644974300, st_ctime=1644973968)
>>> open(sc, "r").read()
'1'
>>> open(o, "r").read()
'12'

In the above example, you can see the shadow copy file and the original file. Their mode and ino are the same, but their modified time and contents are different

----------
components: Windows
messages: 413307
nosy: nijave, paul.moore, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: os.path.samefile incorrect results for shadow copies
type: behavior
versions: Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46763>
_______________________________________


More information about the New-bugs-announce mailing list