diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 2002-08-05 21:53:57 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 2002-08-05 21:53:57 (GMT) |
commit | 0a9d7559e8e07336860fb2aa901c1ba8b77b5921 (patch) | |
tree | 4b700a5423ba81e356f09b505d4ee23719d6ee40 /Mac | |
parent | 11845e00b267e30f87bbb2f2e7039fe9fe3fa594 (diff) | |
download | cpython-0a9d7559e8e07336860fb2aa901c1ba8b77b5921.zip cpython-0a9d7559e8e07336860fb2aa901c1ba8b77b5921.tar.gz cpython-0a9d7559e8e07336860fb2aa901c1ba8b77b5921.tar.bz2 |
In copy() don't try to obtain an FSSpec until we know the destination
exists. Partial fix for #585923.
Diffstat (limited to 'Mac')
-rw-r--r-- | Mac/Lib/macostools.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/Mac/Lib/macostools.py b/Mac/Lib/macostools.py index ca0c7c6..5b94ee2 100644 --- a/Mac/Lib/macostools.py +++ b/Mac/Lib/macostools.py @@ -27,6 +27,8 @@ BUFSIZ=0x80000 # Copy in 0.5Mb chunks def mkalias(src, dst, relative=None): """Create a finder alias""" srcfss = macfs.FSSpec(src) + # The next line will fail under unix-Python if the destination + # doesn't exist yet. We should change this code to be fsref-based. dstfss = macfs.FSSpec(dst) if relative: relativefss = macfs.FSSpec(relative) @@ -82,13 +84,15 @@ def touched_ae(dst): def copy(src, dst, createpath=0, copydates=1, forcetype=None): """Copy a file, including finder info, resource fork, etc""" + if hasattr(src, 'as_pathname'): + src = src.as_pathname() + if hasattr(dst, 'as_pathname'): + dst = dst.as_pathname() if createpath: mkdirs(os.path.split(dst)[0]) - srcfss = macfs.FSSpec(src) - dstfss = macfs.FSSpec(dst) - ifp = open(srcfss.as_pathname(), 'rb') - ofp = open(dstfss.as_pathname(), 'wb') + ifp = open(src, 'rb') + ofp = open(dst, 'wb') d = ifp.read(BUFSIZ) while d: ofp.write(d) @@ -96,8 +100,8 @@ def copy(src, dst, createpath=0, copydates=1, forcetype=None): ifp.close() ofp.close() - ifp = openrf(srcfss.as_pathname(), '*rb') - ofp = openrf(dstfss.as_pathname(), '*wb') + ifp = openrf(src, '*rb') + ofp = openrf(dst, '*wb') d = ifp.read(BUFSIZ) while d: ofp.write(d) @@ -105,6 +109,8 @@ def copy(src, dst, createpath=0, copydates=1, forcetype=None): ifp.close() ofp.close() + srcfss = macfs.FSSpec(src) + dstfss = macfs.FSSpec(dst) sf = srcfss.GetFInfo() df = dstfss.GetFInfo() df.Creator, df.Type = sf.Creator, sf.Type |