def save_data(self, data):
# Age data
if hasattr(data, '__len__') and len(data) > self.GROOM_THRESHOLD:
for i, e in enumerate(data):
data[i] = ZEntry(e.path, int(e.rank * self.GROOM_LEVEL), e.time)
# Use a temporary file to minimize time the file is open and minimize clobbering
from tempfile import NamedTemporaryFile
with NamedTemporaryFile('wt', encoding=sys.getfilesystemencoding()) as f:
for e in data:
f.write("{}|{}|{}\n".format(e.path, int(e.rank), int(e.time.timestamp())))
f.flush()
if self.Z_OWNER:
shutil.chown(f.name, user=self.Z_OWNER)
# On POSIX, rename() is atomic and will clobber
# On Windows, neither of these is true, so remove first.
from xonsh.platform import ON_WINDOWS
if ON_WINDOWS and os.path.exists(self.Z_DATA):
os.remove(self.Z_DATA)
shutil.copy(f.name, self.Z_DATA)
评论列表
文章目录