mirror of https://github.com/python/cpython
Fix [issue4038] py3k error in distutils file_copy exception handlers. r=martin.
This commit is contained in:
parent
e5384b0886
commit
d12dcaea3e
|
@ -30,31 +30,27 @@ def _copy_file_contents(src, dst, buffer_size=16*1024):
|
||||||
try:
|
try:
|
||||||
fsrc = open(src, 'rb')
|
fsrc = open(src, 'rb')
|
||||||
except os.error as e:
|
except os.error as e:
|
||||||
(errno, errstr) = e
|
raise DistutilsFileError("could not open '%s': %s" % (src, e.strerror))
|
||||||
raise DistutilsFileError("could not open '%s': %s" % (src, errstr))
|
|
||||||
|
|
||||||
if os.path.exists(dst):
|
if os.path.exists(dst):
|
||||||
try:
|
try:
|
||||||
os.unlink(dst)
|
os.unlink(dst)
|
||||||
except os.error as e:
|
except os.error as e:
|
||||||
(errno, errstr) = e
|
|
||||||
raise DistutilsFileError(
|
raise DistutilsFileError(
|
||||||
"could not delete '%s': %s" % (dst, errstr))
|
"could not delete '%s': %s" % (dst, e.strerror))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
fdst = open(dst, 'wb')
|
fdst = open(dst, 'wb')
|
||||||
except os.error as e:
|
except os.error as e:
|
||||||
(errno, errstr) = e
|
|
||||||
raise DistutilsFileError(
|
raise DistutilsFileError(
|
||||||
"could not create '%s': %s" % (dst, errstr))
|
"could not create '%s': %s" % (dst, e.strerror))
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
buf = fsrc.read(buffer_size)
|
buf = fsrc.read(buffer_size)
|
||||||
except os.error as e:
|
except os.error as e:
|
||||||
(errno, errstr) = e
|
|
||||||
raise DistutilsFileError(
|
raise DistutilsFileError(
|
||||||
"could not read from '%s': %s" % (src, errstr))
|
"could not read from '%s': %s" % (src, e.strerror))
|
||||||
|
|
||||||
if not buf:
|
if not buf:
|
||||||
break
|
break
|
||||||
|
@ -62,9 +58,8 @@ def _copy_file_contents(src, dst, buffer_size=16*1024):
|
||||||
try:
|
try:
|
||||||
fdst.write(buf)
|
fdst.write(buf)
|
||||||
except os.error as e:
|
except os.error as e:
|
||||||
(errno, errstr) = e
|
|
||||||
raise DistutilsFileError(
|
raise DistutilsFileError(
|
||||||
"could not write to '%s': %s" % (dst, errstr))
|
"could not write to '%s': %s" % (dst, e.strerror))
|
||||||
finally:
|
finally:
|
||||||
if fdst:
|
if fdst:
|
||||||
fdst.close()
|
fdst.close()
|
||||||
|
|
Loading…
Reference in New Issue