mirror of
https://github.com/python/cpython.git
synced 2025-12-04 16:43:27 +00:00
In copy() don't try to obtain an FSSpec until we know the destination
exists. Partial fix for #585923.
This commit is contained in:
parent
11845e00b2
commit
0a9d7559e8
1 changed files with 25 additions and 19 deletions
|
|
@ -27,6 +27,8 @@ BUFSIZ=0x80000 # Copy in 0.5Mb chunks
|
||||||
def mkalias(src, dst, relative=None):
|
def mkalias(src, dst, relative=None):
|
||||||
"""Create a finder alias"""
|
"""Create a finder alias"""
|
||||||
srcfss = macfs.FSSpec(src)
|
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)
|
dstfss = macfs.FSSpec(dst)
|
||||||
if relative:
|
if relative:
|
||||||
relativefss = macfs.FSSpec(relative)
|
relativefss = macfs.FSSpec(relative)
|
||||||
|
|
@ -82,29 +84,33 @@ def touched_ae(dst):
|
||||||
|
|
||||||
def copy(src, dst, createpath=0, copydates=1, forcetype=None):
|
def copy(src, dst, createpath=0, copydates=1, forcetype=None):
|
||||||
"""Copy a file, including finder info, resource fork, etc"""
|
"""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:
|
if createpath:
|
||||||
mkdirs(os.path.split(dst)[0])
|
mkdirs(os.path.split(dst)[0])
|
||||||
|
|
||||||
|
ifp = open(src, 'rb')
|
||||||
|
ofp = open(dst, 'wb')
|
||||||
|
d = ifp.read(BUFSIZ)
|
||||||
|
while d:
|
||||||
|
ofp.write(d)
|
||||||
|
d = ifp.read(BUFSIZ)
|
||||||
|
ifp.close()
|
||||||
|
ofp.close()
|
||||||
|
|
||||||
|
ifp = openrf(src, '*rb')
|
||||||
|
ofp = openrf(dst, '*wb')
|
||||||
|
d = ifp.read(BUFSIZ)
|
||||||
|
while d:
|
||||||
|
ofp.write(d)
|
||||||
|
d = ifp.read(BUFSIZ)
|
||||||
|
ifp.close()
|
||||||
|
ofp.close()
|
||||||
|
|
||||||
srcfss = macfs.FSSpec(src)
|
srcfss = macfs.FSSpec(src)
|
||||||
dstfss = macfs.FSSpec(dst)
|
dstfss = macfs.FSSpec(dst)
|
||||||
|
|
||||||
ifp = open(srcfss.as_pathname(), 'rb')
|
|
||||||
ofp = open(dstfss.as_pathname(), 'wb')
|
|
||||||
d = ifp.read(BUFSIZ)
|
|
||||||
while d:
|
|
||||||
ofp.write(d)
|
|
||||||
d = ifp.read(BUFSIZ)
|
|
||||||
ifp.close()
|
|
||||||
ofp.close()
|
|
||||||
|
|
||||||
ifp = openrf(srcfss.as_pathname(), '*rb')
|
|
||||||
ofp = openrf(dstfss.as_pathname(), '*wb')
|
|
||||||
d = ifp.read(BUFSIZ)
|
|
||||||
while d:
|
|
||||||
ofp.write(d)
|
|
||||||
d = ifp.read(BUFSIZ)
|
|
||||||
ifp.close()
|
|
||||||
ofp.close()
|
|
||||||
|
|
||||||
sf = srcfss.GetFInfo()
|
sf = srcfss.GetFInfo()
|
||||||
df = dstfss.GetFInfo()
|
df = dstfss.GetFInfo()
|
||||||
df.Creator, df.Type = sf.Creator, sf.Type
|
df.Creator, df.Type = sf.Creator, sf.Type
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue