Guido van Rossum | e7b146f | 2000-02-04 15:28:42 +0000 | [diff] [blame] | 1 | """Utility functions for copying files and directory trees. |
Guido van Rossum | 9d0a3df | 1997-04-29 14:45:19 +0000 | [diff] [blame] | 2 | |
Guido van Rossum | 959fa01 | 1999-08-18 20:03:17 +0000 | [diff] [blame] | 3 | XXX The functions here don't copy the resource fork or other metadata on Mac. |
Guido van Rossum | 9d0a3df | 1997-04-29 14:45:19 +0000 | [diff] [blame] | 4 | |
| 5 | """ |
Guido van Rossum | c636014 | 1990-10-13 19:23:40 +0000 | [diff] [blame] | 6 | |
Guido van Rossum | c96207a | 1992-03-31 18:55:40 +0000 | [diff] [blame] | 7 | import os |
Guido van Rossum | 83c03e2 | 1999-02-23 23:07:51 +0000 | [diff] [blame] | 8 | import sys |
Guido van Rossum | 9d0a3df | 1997-04-29 14:45:19 +0000 | [diff] [blame] | 9 | import stat |
Brett Cannon | 1c3fa18 | 2004-06-19 21:11:35 +0000 | [diff] [blame] | 10 | from os.path import abspath |
Georg Brandl | 2ee470f | 2008-07-16 12:55:28 +0000 | [diff] [blame] | 11 | import fnmatch |
Antoine Pitrou | 9f274b1 | 2010-03-22 20:12:40 +0000 | [diff] [blame] | 12 | import errno |
Guido van Rossum | c636014 | 1990-10-13 19:23:40 +0000 | [diff] [blame] | 13 | |
Skip Montanaro | 0de6580 | 2001-02-15 22:15:14 +0000 | [diff] [blame] | 14 | __all__ = ["copyfileobj","copyfile","copymode","copystat","copy","copy2", |
Antoine Pitrou | 7fff096 | 2009-05-01 21:09:44 +0000 | [diff] [blame] | 15 | "copytree","move","rmtree","Error", "SpecialFileError"] |
Martin v. Löwis | e9ce0b0 | 2002-10-07 13:23:24 +0000 | [diff] [blame] | 16 | |
Neal Norwitz | 4ce69a5 | 2005-09-01 00:45:28 +0000 | [diff] [blame] | 17 | class Error(EnvironmentError): |
Martin v. Löwis | e9ce0b0 | 2002-10-07 13:23:24 +0000 | [diff] [blame] | 18 | pass |
Guido van Rossum | c636014 | 1990-10-13 19:23:40 +0000 | [diff] [blame] | 19 | |
Antoine Pitrou | 7fff096 | 2009-05-01 21:09:44 +0000 | [diff] [blame] | 20 | class SpecialFileError(EnvironmentError): |
| 21 | """Raised when trying to do a kind of operation (e.g. copying) which is |
| 22 | not supported on a special file (e.g. a named pipe)""" |
| 23 | |
Georg Brandl | 6aa2d1f | 2008-08-12 08:35:52 +0000 | [diff] [blame] | 24 | try: |
| 25 | WindowsError |
| 26 | except NameError: |
| 27 | WindowsError = None |
| 28 | |
Greg Stein | 42bb8b3 | 2000-07-12 09:55:30 +0000 | [diff] [blame] | 29 | def copyfileobj(fsrc, fdst, length=16*1024): |
| 30 | """copy data from file-like object fsrc to file-like object fdst""" |
| 31 | while 1: |
| 32 | buf = fsrc.read(length) |
| 33 | if not buf: |
| 34 | break |
| 35 | fdst.write(buf) |
| 36 | |
Johannes Gijsbers | 46f1459 | 2004-08-14 13:30:02 +0000 | [diff] [blame] | 37 | def _samefile(src, dst): |
| 38 | # Macintosh, Unix. |
| 39 | if hasattr(os.path,'samefile'): |
Johannes Gijsbers | f9a098e | 2004-08-14 14:51:01 +0000 | [diff] [blame] | 40 | try: |
| 41 | return os.path.samefile(src, dst) |
| 42 | except OSError: |
| 43 | return False |
Johannes Gijsbers | 46f1459 | 2004-08-14 13:30:02 +0000 | [diff] [blame] | 44 | |
| 45 | # All other platforms: check for same pathname. |
| 46 | return (os.path.normcase(os.path.abspath(src)) == |
| 47 | os.path.normcase(os.path.abspath(dst))) |
Tim Peters | 495ad3c | 2001-01-15 01:36:40 +0000 | [diff] [blame] | 48 | |
Guido van Rossum | c636014 | 1990-10-13 19:23:40 +0000 | [diff] [blame] | 49 | def copyfile(src, dst): |
Guido van Rossum | 9d0a3df | 1997-04-29 14:45:19 +0000 | [diff] [blame] | 50 | """Copy data from src to dst""" |
Johannes Gijsbers | 46f1459 | 2004-08-14 13:30:02 +0000 | [diff] [blame] | 51 | if _samefile(src, dst): |
Collin Winter | ce36ad8 | 2007-08-30 01:19:48 +0000 | [diff] [blame] | 52 | raise Error("`%s` and `%s` are the same file" % (src, dst)) |
Johannes Gijsbers | 46f1459 | 2004-08-14 13:30:02 +0000 | [diff] [blame] | 53 | |
Antoine Pitrou | 7fff096 | 2009-05-01 21:09:44 +0000 | [diff] [blame] | 54 | for fn in [src, dst]: |
| 55 | try: |
| 56 | st = os.stat(fn) |
| 57 | except OSError: |
| 58 | # File most likely does not exist |
| 59 | pass |
Benjamin Peterson | c0d98aa | 2009-06-05 19:13:27 +0000 | [diff] [blame] | 60 | else: |
| 61 | # XXX What about other special files? (sockets, devices...) |
| 62 | if stat.S_ISFIFO(st.st_mode): |
| 63 | raise SpecialFileError("`%s` is a named pipe" % fn) |
Tarek Ziadé | 9623980 | 2010-05-05 22:39:31 +0000 | [diff] [blame] | 64 | |
| 65 | with open(src, 'rb') as fsrc: |
| 66 | with open(dst, 'wb') as fdst: |
| 67 | copyfileobj(fsrc, fdst) |
Guido van Rossum | c636014 | 1990-10-13 19:23:40 +0000 | [diff] [blame] | 68 | |
Guido van Rossum | c636014 | 1990-10-13 19:23:40 +0000 | [diff] [blame] | 69 | def copymode(src, dst): |
Guido van Rossum | 9d0a3df | 1997-04-29 14:45:19 +0000 | [diff] [blame] | 70 | """Copy mode bits from src to dst""" |
Tim Peters | 0c94724 | 2001-01-21 20:00:00 +0000 | [diff] [blame] | 71 | if hasattr(os, 'chmod'): |
| 72 | st = os.stat(src) |
Walter Dörwald | 294bbf3 | 2002-06-06 09:48:13 +0000 | [diff] [blame] | 73 | mode = stat.S_IMODE(st.st_mode) |
Tim Peters | 0c94724 | 2001-01-21 20:00:00 +0000 | [diff] [blame] | 74 | os.chmod(dst, mode) |
Guido van Rossum | c636014 | 1990-10-13 19:23:40 +0000 | [diff] [blame] | 75 | |
Guido van Rossum | c636014 | 1990-10-13 19:23:40 +0000 | [diff] [blame] | 76 | def copystat(src, dst): |
Thomas Wouters | cf297e4 | 2007-02-23 15:07:44 +0000 | [diff] [blame] | 77 | """Copy all stat info (mode bits, atime, mtime, flags) from src to dst""" |
Guido van Rossum | a2baf46 | 1997-04-29 14:06:46 +0000 | [diff] [blame] | 78 | st = os.stat(src) |
Walter Dörwald | 294bbf3 | 2002-06-06 09:48:13 +0000 | [diff] [blame] | 79 | mode = stat.S_IMODE(st.st_mode) |
Tim Peters | 0c94724 | 2001-01-21 20:00:00 +0000 | [diff] [blame] | 80 | if hasattr(os, 'utime'): |
Walter Dörwald | 294bbf3 | 2002-06-06 09:48:13 +0000 | [diff] [blame] | 81 | os.utime(dst, (st.st_atime, st.st_mtime)) |
Tim Peters | 0c94724 | 2001-01-21 20:00:00 +0000 | [diff] [blame] | 82 | if hasattr(os, 'chmod'): |
| 83 | os.chmod(dst, mode) |
Thomas Wouters | cf297e4 | 2007-02-23 15:07:44 +0000 | [diff] [blame] | 84 | if hasattr(os, 'chflags') and hasattr(st, 'st_flags'): |
Antoine Pitrou | 9f274b1 | 2010-03-22 20:12:40 +0000 | [diff] [blame] | 85 | try: |
| 86 | os.chflags(dst, st.st_flags) |
| 87 | except OSError as why: |
| 88 | if not hasattr(errno, 'EOPNOTSUPP') or why.errno != errno.EOPNOTSUPP: |
| 89 | raise |
Guido van Rossum | 9d0a3df | 1997-04-29 14:45:19 +0000 | [diff] [blame] | 90 | |
Guido van Rossum | c636014 | 1990-10-13 19:23:40 +0000 | [diff] [blame] | 91 | def copy(src, dst): |
Guido van Rossum | 9d0a3df | 1997-04-29 14:45:19 +0000 | [diff] [blame] | 92 | """Copy data and mode bits ("cp src dst"). |
Tim Peters | 495ad3c | 2001-01-15 01:36:40 +0000 | [diff] [blame] | 93 | |
Guido van Rossum | 9d0a3df | 1997-04-29 14:45:19 +0000 | [diff] [blame] | 94 | The destination may be a directory. |
| 95 | |
| 96 | """ |
Guido van Rossum | a2baf46 | 1997-04-29 14:06:46 +0000 | [diff] [blame] | 97 | if os.path.isdir(dst): |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 98 | dst = os.path.join(dst, os.path.basename(src)) |
Guido van Rossum | a2baf46 | 1997-04-29 14:06:46 +0000 | [diff] [blame] | 99 | copyfile(src, dst) |
| 100 | copymode(src, dst) |
Guido van Rossum | c636014 | 1990-10-13 19:23:40 +0000 | [diff] [blame] | 101 | |
Guido van Rossum | c636014 | 1990-10-13 19:23:40 +0000 | [diff] [blame] | 102 | def copy2(src, dst): |
Guido van Rossum | 9d0a3df | 1997-04-29 14:45:19 +0000 | [diff] [blame] | 103 | """Copy data and all stat info ("cp -p src dst"). |
| 104 | |
| 105 | The destination may be a directory. |
| 106 | |
| 107 | """ |
Guido van Rossum | a2baf46 | 1997-04-29 14:06:46 +0000 | [diff] [blame] | 108 | if os.path.isdir(dst): |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 109 | dst = os.path.join(dst, os.path.basename(src)) |
Guido van Rossum | a2baf46 | 1997-04-29 14:06:46 +0000 | [diff] [blame] | 110 | copyfile(src, dst) |
| 111 | copystat(src, dst) |
Guido van Rossum | c636014 | 1990-10-13 19:23:40 +0000 | [diff] [blame] | 112 | |
Georg Brandl | 2ee470f | 2008-07-16 12:55:28 +0000 | [diff] [blame] | 113 | def ignore_patterns(*patterns): |
| 114 | """Function that can be used as copytree() ignore parameter. |
Guido van Rossum | 9d0a3df | 1997-04-29 14:45:19 +0000 | [diff] [blame] | 115 | |
Georg Brandl | 2ee470f | 2008-07-16 12:55:28 +0000 | [diff] [blame] | 116 | Patterns is a sequence of glob-style patterns |
| 117 | that are used to exclude files""" |
| 118 | def _ignore_patterns(path, names): |
| 119 | ignored_names = [] |
| 120 | for pattern in patterns: |
| 121 | ignored_names.extend(fnmatch.filter(names, pattern)) |
| 122 | return set(ignored_names) |
| 123 | return _ignore_patterns |
| 124 | |
| 125 | def copytree(src, dst, symlinks=False, ignore=None): |
Guido van Rossum | 9d0a3df | 1997-04-29 14:45:19 +0000 | [diff] [blame] | 126 | """Recursively copy a directory tree using copy2(). |
| 127 | |
| 128 | The destination directory must not already exist. |
Neal Norwitz | a4c93b6 | 2003-02-23 21:36:32 +0000 | [diff] [blame] | 129 | If exception(s) occur, an Error is raised with a list of reasons. |
Guido van Rossum | 9d0a3df | 1997-04-29 14:45:19 +0000 | [diff] [blame] | 130 | |
| 131 | If the optional symlinks flag is true, symbolic links in the |
| 132 | source tree result in symbolic links in the destination tree; if |
| 133 | it is false, the contents of the files pointed to by symbolic |
| 134 | links are copied. |
| 135 | |
Georg Brandl | 2ee470f | 2008-07-16 12:55:28 +0000 | [diff] [blame] | 136 | The optional ignore argument is a callable. If given, it |
| 137 | is called with the `src` parameter, which is the directory |
| 138 | being visited by copytree(), and `names` which is the list of |
| 139 | `src` contents, as returned by os.listdir(): |
| 140 | |
| 141 | callable(src, names) -> ignored_names |
| 142 | |
| 143 | Since copytree() is called recursively, the callable will be |
| 144 | called once for each directory that is copied. It returns a |
| 145 | list of names relative to the `src` directory that should |
| 146 | not be copied. |
| 147 | |
Guido van Rossum | 9d0a3df | 1997-04-29 14:45:19 +0000 | [diff] [blame] | 148 | XXX Consider this example code rather than the ultimate tool. |
| 149 | |
| 150 | """ |
Guido van Rossum | a2baf46 | 1997-04-29 14:06:46 +0000 | [diff] [blame] | 151 | names = os.listdir(src) |
Georg Brandl | 2ee470f | 2008-07-16 12:55:28 +0000 | [diff] [blame] | 152 | if ignore is not None: |
| 153 | ignored_names = ignore(src, names) |
| 154 | else: |
| 155 | ignored_names = set() |
| 156 | |
Johannes Gijsbers | e4172ea | 2005-01-08 12:31:29 +0000 | [diff] [blame] | 157 | os.makedirs(dst) |
Martin v. Löwis | e9ce0b0 | 2002-10-07 13:23:24 +0000 | [diff] [blame] | 158 | errors = [] |
Guido van Rossum | a2baf46 | 1997-04-29 14:06:46 +0000 | [diff] [blame] | 159 | for name in names: |
Georg Brandl | 2ee470f | 2008-07-16 12:55:28 +0000 | [diff] [blame] | 160 | if name in ignored_names: |
| 161 | continue |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 162 | srcname = os.path.join(src, name) |
| 163 | dstname = os.path.join(dst, name) |
| 164 | try: |
| 165 | if symlinks and os.path.islink(srcname): |
| 166 | linkto = os.readlink(srcname) |
| 167 | os.symlink(linkto, dstname) |
| 168 | elif os.path.isdir(srcname): |
Georg Brandl | 2ee470f | 2008-07-16 12:55:28 +0000 | [diff] [blame] | 169 | copytree(srcname, dstname, symlinks, ignore) |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 170 | else: |
Antoine Pitrou | 7fff096 | 2009-05-01 21:09:44 +0000 | [diff] [blame] | 171 | # Will raise a SpecialFileError for unsupported file types |
Guido van Rossum | 45e2fbc | 1998-03-26 21:13:24 +0000 | [diff] [blame] | 172 | copy2(srcname, dstname) |
Georg Brandl | a1be88e | 2005-08-31 22:48:45 +0000 | [diff] [blame] | 173 | # catch the Error from the recursive copytree so that we can |
| 174 | # continue with other files |
Guido van Rossum | b940e11 | 2007-01-10 16:19:56 +0000 | [diff] [blame] | 175 | except Error as err: |
Georg Brandl | a1be88e | 2005-08-31 22:48:45 +0000 | [diff] [blame] | 176 | errors.extend(err.args[0]) |
Antoine Pitrou | 7fff096 | 2009-05-01 21:09:44 +0000 | [diff] [blame] | 177 | except EnvironmentError as why: |
| 178 | errors.append((srcname, dstname, str(why))) |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 179 | try: |
| 180 | copystat(src, dst) |
Guido van Rossum | b940e11 | 2007-01-10 16:19:56 +0000 | [diff] [blame] | 181 | except OSError as why: |
Georg Brandl | 6aa2d1f | 2008-08-12 08:35:52 +0000 | [diff] [blame] | 182 | if WindowsError is not None and isinstance(why, WindowsError): |
| 183 | # Copying file access times may fail on Windows |
| 184 | pass |
| 185 | else: |
| 186 | errors.extend((src, dst, str(why))) |
Martin v. Löwis | e9ce0b0 | 2002-10-07 13:23:24 +0000 | [diff] [blame] | 187 | if errors: |
Collin Winter | ce36ad8 | 2007-08-30 01:19:48 +0000 | [diff] [blame] | 188 | raise Error(errors) |
Guido van Rossum | d767329 | 1998-02-06 21:38:09 +0000 | [diff] [blame] | 189 | |
Barry Warsaw | 234d9a9 | 2003-01-24 17:36:15 +0000 | [diff] [blame] | 190 | def rmtree(path, ignore_errors=False, onerror=None): |
Guido van Rossum | d767329 | 1998-02-06 21:38:09 +0000 | [diff] [blame] | 191 | """Recursively delete a directory tree. |
| 192 | |
Johannes Gijsbers | ef5ffc4 | 2004-10-31 12:05:31 +0000 | [diff] [blame] | 193 | If ignore_errors is set, errors are ignored; otherwise, if onerror |
| 194 | is set, it is called to handle the error with arguments (func, |
| 195 | path, exc_info) where func is os.listdir, os.remove, or os.rmdir; |
| 196 | path is the argument to that function that caused it to fail; and |
| 197 | exc_info is a tuple returned by sys.exc_info(). If ignore_errors |
| 198 | is false and onerror is None, an exception is raised. |
| 199 | |
Guido van Rossum | d767329 | 1998-02-06 21:38:09 +0000 | [diff] [blame] | 200 | """ |
Johannes Gijsbers | ef5ffc4 | 2004-10-31 12:05:31 +0000 | [diff] [blame] | 201 | if ignore_errors: |
| 202 | def onerror(*args): |
Barry Warsaw | 234d9a9 | 2003-01-24 17:36:15 +0000 | [diff] [blame] | 203 | pass |
Johannes Gijsbers | ef5ffc4 | 2004-10-31 12:05:31 +0000 | [diff] [blame] | 204 | elif onerror is None: |
| 205 | def onerror(*args): |
| 206 | raise |
Christian Heimes | 9bd667a | 2008-01-20 15:14:11 +0000 | [diff] [blame] | 207 | try: |
| 208 | if os.path.islink(path): |
| 209 | # symlinks to directories are forbidden, see bug #1669 |
| 210 | raise OSError("Cannot call rmtree on a symbolic link") |
| 211 | except OSError: |
| 212 | onerror(os.path.islink, path, sys.exc_info()) |
| 213 | # can't continue even if onerror hook returns |
| 214 | return |
Johannes Gijsbers | ef5ffc4 | 2004-10-31 12:05:31 +0000 | [diff] [blame] | 215 | names = [] |
| 216 | try: |
| 217 | names = os.listdir(path) |
Guido van Rossum | b940e11 | 2007-01-10 16:19:56 +0000 | [diff] [blame] | 218 | except os.error as err: |
Johannes Gijsbers | ef5ffc4 | 2004-10-31 12:05:31 +0000 | [diff] [blame] | 219 | onerror(os.listdir, path, sys.exc_info()) |
| 220 | for name in names: |
| 221 | fullname = os.path.join(path, name) |
| 222 | try: |
| 223 | mode = os.lstat(fullname).st_mode |
| 224 | except os.error: |
| 225 | mode = 0 |
| 226 | if stat.S_ISDIR(mode): |
| 227 | rmtree(fullname, ignore_errors, onerror) |
Barry Warsaw | 234d9a9 | 2003-01-24 17:36:15 +0000 | [diff] [blame] | 228 | else: |
Johannes Gijsbers | ef5ffc4 | 2004-10-31 12:05:31 +0000 | [diff] [blame] | 229 | try: |
| 230 | os.remove(fullname) |
Guido van Rossum | b940e11 | 2007-01-10 16:19:56 +0000 | [diff] [blame] | 231 | except os.error as err: |
Johannes Gijsbers | ef5ffc4 | 2004-10-31 12:05:31 +0000 | [diff] [blame] | 232 | onerror(os.remove, fullname, sys.exc_info()) |
| 233 | try: |
| 234 | os.rmdir(path) |
| 235 | except os.error: |
| 236 | onerror(os.rmdir, path, sys.exc_info()) |
Guido van Rossum | d767329 | 1998-02-06 21:38:09 +0000 | [diff] [blame] | 237 | |
Martin v. Löwis | e9ce0b0 | 2002-10-07 13:23:24 +0000 | [diff] [blame] | 238 | |
Christian Heimes | ada8c3b | 2008-03-18 18:26:33 +0000 | [diff] [blame] | 239 | def _basename(path): |
| 240 | # A basename() variant which first strips the trailing slash, if present. |
| 241 | # Thus we always get the last component of the path, even for directories. |
| 242 | return os.path.basename(path.rstrip(os.path.sep)) |
| 243 | |
| 244 | def move(src, dst): |
| 245 | """Recursively move a file or directory to another location. This is |
| 246 | similar to the Unix "mv" command. |
| 247 | |
| 248 | If the destination is a directory or a symlink to a directory, the source |
| 249 | is moved inside the directory. The destination path must not already |
| 250 | exist. |
| 251 | |
| 252 | If the destination already exists but is not a directory, it may be |
| 253 | overwritten depending on os.rename() semantics. |
| 254 | |
| 255 | If the destination is on our current filesystem, then rename() is used. |
| 256 | Otherwise, src is copied to the destination and then removed. |
Martin v. Löwis | e9ce0b0 | 2002-10-07 13:23:24 +0000 | [diff] [blame] | 257 | A lot more could be done here... A look at a mv.c shows a lot of |
| 258 | the issues this implementation glosses over. |
| 259 | |
| 260 | """ |
Christian Heimes | ada8c3b | 2008-03-18 18:26:33 +0000 | [diff] [blame] | 261 | real_dst = dst |
| 262 | if os.path.isdir(dst): |
| 263 | real_dst = os.path.join(dst, _basename(src)) |
| 264 | if os.path.exists(real_dst): |
| 265 | raise Error("Destination path '%s' already exists" % real_dst) |
Martin v. Löwis | e9ce0b0 | 2002-10-07 13:23:24 +0000 | [diff] [blame] | 266 | try: |
Christian Heimes | ada8c3b | 2008-03-18 18:26:33 +0000 | [diff] [blame] | 267 | os.rename(src, real_dst) |
Martin v. Löwis | e9ce0b0 | 2002-10-07 13:23:24 +0000 | [diff] [blame] | 268 | except OSError: |
| 269 | if os.path.isdir(src): |
Benjamin Peterson | 247a9b8 | 2009-02-20 04:09:19 +0000 | [diff] [blame] | 270 | if _destinsrc(src, dst): |
Collin Winter | ce36ad8 | 2007-08-30 01:19:48 +0000 | [diff] [blame] | 271 | raise Error("Cannot move a directory '%s' into itself '%s'." % (src, dst)) |
Christian Heimes | ada8c3b | 2008-03-18 18:26:33 +0000 | [diff] [blame] | 272 | copytree(src, real_dst, symlinks=True) |
Martin v. Löwis | e9ce0b0 | 2002-10-07 13:23:24 +0000 | [diff] [blame] | 273 | rmtree(src) |
| 274 | else: |
Christian Heimes | ada8c3b | 2008-03-18 18:26:33 +0000 | [diff] [blame] | 275 | copy2(src, real_dst) |
Martin v. Löwis | e9ce0b0 | 2002-10-07 13:23:24 +0000 | [diff] [blame] | 276 | os.unlink(src) |
Brett Cannon | 1c3fa18 | 2004-06-19 21:11:35 +0000 | [diff] [blame] | 277 | |
Benjamin Peterson | 247a9b8 | 2009-02-20 04:09:19 +0000 | [diff] [blame] | 278 | def _destinsrc(src, dst): |
Antoine Pitrou | 0dcc3cd | 2009-01-29 20:26:59 +0000 | [diff] [blame] | 279 | src = abspath(src) |
| 280 | dst = abspath(dst) |
| 281 | if not src.endswith(os.path.sep): |
| 282 | src += os.path.sep |
| 283 | if not dst.endswith(os.path.sep): |
| 284 | dst += os.path.sep |
| 285 | return dst.startswith(src) |