Kaydet (Commit) 277206b0 authored tarafından Guido van Rossum's avatar Guido van Rossum

Improvements to copyfile(): open the files in binary mode, and close

them in a finally clause.
üst e9a0732c
# Module 'shutil' -- utility functions usable in a shell-like program
# XXX The copy*() functions here don't copy the data fork on Mac
import os
......@@ -8,12 +9,21 @@ MODEBITS = 010000 # Lower 12 mode bits
# Copy data from src to dst
#
def copyfile(src, dst):
fsrc = open(src, 'r')
fdst = open(dst, 'w')
while 1:
buf = fsrc.read(16*1024)
if not buf: break
fdst.write(buf)
fsrc = None
fdst = None
try:
fsrc = open(src, 'rb')
fdst = open(dst, 'wb')
while 1:
buf = fsrc.read(16*1024)
if not buf:
break
fdst.write(buf)
finally:
if fdst:
fdst.close()
if fsrc:
fsrc.close()
# Copy mode bits from src to dst
#
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment