This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Deniz Bozyigit
Recipients Deniz Bozyigit, paul.moore, steve.dower, tim.golden, zach.ware
Date 2018-06-22.00:38:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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:

The error originates in the library in 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:

---      2018-06-22 02:14:27.145744900 +0200
+++  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?
Date User Action Args
2018-06-22 00:38:26Deniz Bozyigitsetrecipients: + Deniz Bozyigit, paul.moore, tim.golden, zach.ware, steve.dower
2018-06-22 00:38:26Deniz Bozyigitsetmessageid: <>
2018-06-22 00:38:26Deniz Bozyigitlinkissue33935 messages
2018-06-22 00:38:24Deniz Bozyigitcreate