/usr/lib/python3/dist-packages/S3/HashCache.py is in s3cmd 2.0.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | # -*- coding: utf-8 -*-
from __future__ import absolute_import
try:
# python 3 support
import cPickle as pickle
except ImportError:
import pickle
from .Utils import deunicodise
class HashCache(object):
def __init__(self):
self.inodes = dict()
def add(self, dev, inode, mtime, size, md5):
if dev == 0 or inode == 0: return # Windows
if dev not in self.inodes:
self.inodes[dev] = dict()
if inode not in self.inodes[dev]:
self.inodes[dev][inode] = dict()
self.inodes[dev][inode][mtime] = dict(md5=md5, size=size)
def md5(self, dev, inode, mtime, size):
try:
d = self.inodes[dev][inode][mtime]
if d['size'] != size:
return None
except:
return None
return d['md5']
def mark_all_for_purge(self):
for d in self.inodes.keys():
for i in self.inodes[d].keys():
for c in self.inodes[d][i].keys():
self.inodes[d][i][c]['purge'] = True
def unmark_for_purge(self, dev, inode, mtime, size):
try:
d = self.inodes[dev][inode][mtime]
except KeyError:
return
if d['size'] == size and 'purge' in d:
del self.inodes[dev][inode][mtime]['purge']
def purge(self):
for d in self.inodes.keys():
for i in self.inodes[d].keys():
for m in self.inodes[d][i].keys():
if 'purge' in self.inodes[d][i][m]:
del self.inodes[d][i]
break
def save(self, f):
d = dict(inodes=self.inodes, version=1)
with open(deunicodise(f), 'wb') as fp:
pickle.dump(d, fp)
def load(self, f):
with open(deunicodise(f), 'rb') as fp:
d = pickle.load(fp)
if d.get('version') == 1 and 'inodes' in d:
self.inodes = d['inodes']
|