[Fix]: Put file descriptors close() in try and finally statement for document module.
bzr revid: atp@tinyerp.co.in-20101111064707-lltotiioe28zmke1
This commit is contained in:
@@ -71,8 +71,10 @@ class indexer(object):
|
||||
pass
|
||||
|
||||
fp = open(realfile,'rb')
|
||||
content2 = fp.read()
|
||||
fp.close()
|
||||
try:
|
||||
content2 = fp.read()
|
||||
finally:
|
||||
fp.close()
|
||||
|
||||
# The not-handled exception may be raised here
|
||||
return self._doIndexContent(content2)
|
||||
@@ -164,8 +166,10 @@ class contentIndex(object):
|
||||
os.close(fd)
|
||||
|
||||
fp = Popen(['file','-b','--mime',fname], shell=False, stdout=PIPE).stdout
|
||||
result = fp.read()
|
||||
fp.close()
|
||||
try:
|
||||
result = fp.read()
|
||||
finally:
|
||||
fp.close()
|
||||
mime2 = result.split(';')[0]
|
||||
self.__logger.debug('File gave us: %s', mime2)
|
||||
# Note that the temporary file still exists now.
|
||||
|
||||
@@ -541,9 +541,11 @@ class document_storage(osv.osv):
|
||||
try:
|
||||
store_fname = self.__get_random_fname(path)
|
||||
fname = os.path.join(path, store_fname)
|
||||
fp = file(fname, 'wb')
|
||||
fp.write(data)
|
||||
fp.close()
|
||||
fp = open(fname, 'wb')
|
||||
try:
|
||||
fp.write(data)
|
||||
finally:
|
||||
fp.close()
|
||||
self._doclog.debug( "Saved data to %s" % fname)
|
||||
filesize = len(data) # os.stat(fname).st_size
|
||||
|
||||
@@ -568,9 +570,11 @@ class document_storage(osv.osv):
|
||||
try:
|
||||
path, npath = self.__prepare_realpath(cr, file_node, ira, boo.path, do_create=True)
|
||||
fname = os.path.join(path, npath[-1])
|
||||
fp = file(fname,'wb')
|
||||
fp.write(data)
|
||||
fp.close()
|
||||
fp = open(fname,'wb')
|
||||
try:
|
||||
fp.write(data)
|
||||
finally:
|
||||
fp.close()
|
||||
self._doclog.debug("Saved data to %s", fname)
|
||||
filesize = len(data) # os.stat(fname).st_size
|
||||
store_fname = os.path.join(*npath)
|
||||
|
||||
Reference in New Issue
Block a user