[Python-checkins] python/dist/src/Lib shutil.py,1.30,1.31

jlgijsbers at users.sourceforge.net jlgijsbers at users.sourceforge.net
Sat Aug 14 15:30:04 CEST 2004


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13343

Modified Files:
	shutil.py 
Log Message:
Raise an exception when src and dst refer to the same file via a hard link or a
symbolic link (bug #851123 / patch #854853, thanks Gregory Ball).


Index: shutil.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/shutil.py,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -d -r1.30 -r1.31
*** shutil.py	14 Jul 2004 00:45:59 -0000	1.30
--- shutil.py	14 Aug 2004 13:30:01 -0000	1.31
***************
*** 25,38 ****
          fdst.write(buf)
  
  
  def copyfile(src, dst):
      """Copy data from src to dst"""
      fsrc = None
      fdst = None
-     # check for same pathname; all platforms
-     _src = os.path.normcase(os.path.abspath(src))
-     _dst = os.path.normcase(os.path.abspath(dst))
-     if _src == _dst:
-         return
      try:
          fsrc = open(src, 'rb')
--- 25,44 ----
          fdst.write(buf)
  
+ def _samefile(src, dst):
+     # Macintosh, Unix.
+     if hasattr(os.path,'samefile'):
+         return os.path.samefile(src, dst)
+ 
+     # All other platforms: check for same pathname.
+     return (os.path.normcase(os.path.abspath(src)) ==
+             os.path.normcase(os.path.abspath(dst)))
  
  def copyfile(src, dst):
      """Copy data from src to dst"""
+     if _samefile(src, dst):
+         raise Error, "`%s` and `%s` are the same file" % (src, dst)
+ 
      fsrc = None
      fdst = None
      try:
          fsrc = open(src, 'rb')



More information about the Python-checkins mailing list