if file.type == type:
return file
- def __file_hash(self, filename):
- sha1 = hashlib.sha1()
+ def __file_hash(self, filename, algo="sha256"):
+ h = hashlib.new(algo)
with open(filename) as f:
buf_size = 1024
buf = f.read(buf_size)
while buf:
- sha1.update(buf)
+ h.update(buf)
buf = f.read(buf_size)
- return sha1.hexdigest()
+ return h.hexdigest()
def scan_files(self, basepath="/pub/mirror"):
if not self.path:
continue
logging.info("Hashing %s..." % filename)
- filehash = self.__file_hash(filename)
+ hash_sha256 = self.__file_hash(filename, "sha256")
+ hash_sha1 = self.__file_hash(filename, "sha1")
filesize = os.path.getsize(filename)
# Check if there is a torrent download available for this file:
torrent_hash = self.torrent_read_hash(torrent_file)
self.db.execute("INSERT INTO files(releases, filename, filesize, \
- sha1, torrent_hash) VALUES(%s, %s, %s, %s, %s)",
- self.id, _filename, filesize, filehash, torrent_hash)
+ sha256, sha1, torrent_hash) VALUES(%s, %s, %s, %s, %s, %s)",
+ self.id, _filename, filesize, hash_sha256, hash_sha1, torrent_hash)
# Search for all files that miss a torrent hash.
files = self.db.query("SELECT id, filename FROM files \