mirror of
https://github.com/moparisthebest/HttpUploadComponent
synced 2024-11-24 09:52:15 -05:00
Merge pull request #14 from SamWhited/fix_file_leak
Fix a file handle leak
This commit is contained in:
commit
db06e3edfc
13
server.py
13
server.py
@ -120,13 +120,12 @@ class HttpHandler(BaseHTTPRequestHandler):
|
|||||||
filename = os.path.join(config['storage_path'], path)
|
filename = os.path.join(config['storage_path'], path)
|
||||||
os.makedirs(os.path.dirname(filename))
|
os.makedirs(os.path.dirname(filename))
|
||||||
remaining = length
|
remaining = length
|
||||||
f = open(filename,'wb')
|
with open(filename,'wb') as f:
|
||||||
data = self.rfile.read(4096)
|
data = self.rfile.read(4096)
|
||||||
while data and remaining >= 0:
|
while data and remaining >= 0:
|
||||||
remaining -= len(data)
|
remaining -= len(data)
|
||||||
f.write(data)
|
f.write(data)
|
||||||
data = self.rfile.read(min(4096,remaining))
|
data = self.rfile.read(min(4096,remaining))
|
||||||
f.close()
|
|
||||||
self.send_response(200,'ok')
|
self.send_response(200,'ok')
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user