[issue33935] shutil.copyfile throws incorrect SameFileError

2018-06-21 Thread Deniz Bozyigit


New submission from Deniz Bozyigit :

When using shutil.copyfile on the Google Drive File Stream file system, a 
incorrect SameFileError can occur. 

MWE (assuming foo.txt exists in your google drive G:\\):
>>> f1 = 'G:\\My Drive\\foo.txt'
>>> f2 = 'G:\\My Drive\\foo2.txt'
>>> import shutil
>>> shutil.copyfile(f1, f2)
>>> shutil.copyfile(f1, f2)

--> Last line throws incorrect SameFileError. In comparison, executing the same 
code on a different file system (e.g. local hard drive) will result in no 
errors.

More details described here: https://github.com/jupyter/notebook/issues/3615

The error originates in the library in generalpath.py in the function samestat: 
Google Drive File Stream reports inode==0 which makes os.path.samefile(f1, f2) 
== True for any files f1 and f2 on Google File Stream.

I propose the following patch, which currently works for me:

--- genericpath.py  2018-06-22 02:14:27.145744900 +0200
+++ genericpath_new.py  2018-06-22 02:10:44.485961100 +0200
@@ -86,8 +86,11 @@
 # describing the same file?
 def samestat(s1, s2):
 """Test whether two stat buffers reference the same file"""
-return (s1.st_ino == s2.st_ino and
-s1.st_dev == s2.st_dev)
+return (s1.st_ino != 0 and
+   s2.st_ino != 0 and
+   s1.st_ino == s2.st_ino and
+s1.st_dev == s2.st_dev)
+


 # Are two filenames really pointing to the same file?

--
components: Library (Lib), Windows
messages: 320199
nosy: Deniz Bozyigit, paul.moore, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: shutil.copyfile throws incorrect SameFileError
type: crash
versions: Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8

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



[issue33935] shutil.copyfile throws incorrect SameFileError on Google Drive File Stream

2018-06-21 Thread Deniz Bozyigit


Change by Deniz Bozyigit :


--
title: shutil.copyfile throws incorrect SameFileError -> shutil.copyfile throws 
incorrect SameFileError on Google Drive File Stream

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



[issue33935] shutil.copyfile throws incorrect SameFileError on Google Drive File Stream

2018-06-21 Thread Deniz Bozyigit


Deniz Bozyigit  added the comment:

Hi, thank you for looking into this. I'm aware that the shown patch is not the 
ideal solution and a mere fix to get my jupyter operational. 

An indication on a workable solution could be the _samefile function in shutil 
that wraps os.path.samefile:

def _samefile(src, dst):
# Macintosh, Unix.
if hasattr(os.path, 'samefile'):
try:
return os.path.samefile(src, dst)
except OSError:
return False

# All other platforms: check for same pathname.
return (os.path.normcase(os.path.abspath(src)) ==
os.path.normcase(os.path.abspath(dst)))


I understand that the implicit platform differentiation that is done here (see 
the comment line) is not valid anymore since os.path.samefile is now available 
on windows systems. It seems that for a windows system the here implemented 
file name comparison could be workable (even moving it into os.path.samefile?), 
if the platform is identified correctly.

--

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