Input handlers: more closing to help with windows temp files

This commit is contained in:
Jean-Francois Dockes
2019-07-21 10:03:03 +02:00
parent a1daa8de55
commit af664e7768
4 changed files with 42 additions and 6 deletions
+14 -3
View File
@@ -35,6 +35,7 @@ if not hasrclconfig:
class SevenZipExtractor:
def __init__(self, em):
self.currentindex = 0
self.fp = None
self.em = em
def extractone(self, ipath):
@@ -51,6 +52,10 @@ class SevenZipExtractor:
iseof = rclexecm.RclExecM.eofnext
return (ok, docdata, rclexecm.makebytes(ipath), iseof)
def closefile(self):
if self.fp:
self.fp.close()
###### File type handler api, used by rclexecm ---------->
def openfile(self, params):
filename = params["filename:"]
@@ -65,8 +70,8 @@ class SevenZipExtractor:
self.skiplist = skipped.split(" ")
try:
fp = open(filename, 'rb')
self.sevenzip = Archive7z(fp)
self.fp = open(filename, 'rb')
self.sevenzip = Archive7z(self.fp)
return True
except Exception as err:
self.em.rclog("openfile: failed: [%s]" % err)
@@ -90,6 +95,7 @@ class SevenZipExtractor:
self.currentindex = 0
self.em.setmimetype('text/plain')
if len(self.sevenzip.getnames()) == 0:
self.closefile()
eof = rclexecm.RclExecM.eofnext
else:
eof = rclexecm.RclExecM.noteof
@@ -97,6 +103,7 @@ class SevenZipExtractor:
if self.currentindex >= len(self.sevenzip.getnames()):
#self.em.rclog("getnext: EOF hit")
self.closefile()
return (False, "", "", rclexecm.RclExecM.eofnow)
else:
entryname = self.sevenzip.getnames()[self.currentindex]
@@ -112,9 +119,13 @@ class SevenZipExtractor:
break
self.currentindex += 1
if entryname is None:
self.closefile()
return (False, "", "", rclexecm.RclExecM.eofnow)
ret= self.extractone(entryname)
ret = self.extractone(entryname)
if ret[3] == rclexecm.RclExecM.eofnext or \
ret[3] == rclexecm.RclExecM.eofnow:
self.closefile()
self.currentindex += 1
return ret