[New-bugs-announce] [issue43302] shutil. copy file throws incorrect SameFileError on Google Drive File Stream

Coleman report at bugs.python.org
Mon Feb 22 13:52:18 EST 2021

New submission from Coleman <k.ana70416 at gmail.com>:

When using shuttle. copy file on the Google Drive File Stream file way, an incorrect SameFileError can happen. 

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 contrast, executing the same code on a different file operation(e.g. local hard drive) will result in no errors.

More details described here: 

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

I suggest 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 actually pointing to the very file?

components: Library (Lib)
messages: 387531
nosy: Deniz Bozyigit, White1, alexkowel, eryksun
priority: normal
severity: normal
status: open
title: shutil. copy file throws incorrect SameFileError on Google Drive File Stream
versions: Python 3.7, Python 3.8

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list