Commit 0ddb4ae2 authored by Ken Manheimer's avatar Ken Manheimer

Make non-persistent client cache use tempfile.TemporaryFile, so the

tempfiles do *not* perpetually accumulate.  (TemporaryFile reliably is
removed when the program is done with it, under both windows and
unix.)

ClientCache.__init__(): Set up the first TemporaryFile, and set both
self._p file names to None, to signify use of temp files.

ClientCache.checkSize(): Switch over to other persistent cache file if
self._p has names, or a new TemporaryFile if they're None.

(I included some comments to the code i touched, to ease the passage
of anyone else who winds up on that path...)
parent a06a598f
......@@ -144,7 +144,7 @@ file 0 and file 1.
"""
__version__ = "$Revision: 1.8 $"[11:-2]
__version__ = "$Revision: 1.9 $"[11:-2]
import os, tempfile
from struct import pack, unpack
......@@ -189,12 +189,9 @@ class ClientCache:
current=0
f[1]=None
else:
# Create a temporary cache
self._p=p=map(
lambda i, p=storage:
tempfile.mktemp('.zec'),
(0,1))
self._f=f=[open(p[0],'w+b'), None]
self._f = f = [tempfile.TemporaryFile(suffix='.zec'), None]
# self._p file names 'None' signifies unnamed temp files.
self._p = p = [None, None]
f[0].write(magic)
current=0
......@@ -324,7 +321,12 @@ class ClientCache:
if self._pos+size > self._limit:
current=not self._current
self._current=current
if self._p[current] is not None:
# Persistent cache file:
self._f[current]=open(self._p[current],'w+b')
else:
# Temporary cache file:
self._f[current] = tempfile.TemporaryFile(suffix='.zec')
self._f[current].write(magic)
self._pos=pos=4
......
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