more verbose hash check
This commit is contained in:
@@ -17,6 +17,7 @@ MINSIZE=0
|
|||||||
MIME=magic.open(magic.MAGIC_NONE)
|
MIME=magic.open(magic.MAGIC_NONE)
|
||||||
#MIME=magic.open(magic.MAGIC_MIME)
|
#MIME=magic.open(magic.MAGIC_MIME)
|
||||||
MIME.load()
|
MIME.load()
|
||||||
|
ANIM=['-','\\','|','/','-','_','_']
|
||||||
|
|
||||||
def setup_options():
|
def setup_options():
|
||||||
parser=ArgumentParser(description="Maintains the list of images sqlite file")
|
parser=ArgumentParser(description="Maintains the list of images sqlite file")
|
||||||
@@ -106,7 +107,7 @@ def add_single(conn,filename,change=False,hash=None,minsize=0,fullfile=False):
|
|||||||
fsize=os.path.getsize(filename)
|
fsize=os.path.getsize(filename)
|
||||||
mime=MIME.file(filename.encode('UTF-8'))
|
mime=MIME.file(filename.encode('UTF-8'))
|
||||||
except IOError:
|
except IOError:
|
||||||
print("File not found. Bad link?")
|
print("File '%s' not found. Bad link?"%(filename,))
|
||||||
return
|
return
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
mime="NA"
|
mime="NA"
|
||||||
@@ -310,11 +311,16 @@ def get_folder_contents(db,path):
|
|||||||
def get_md5(filename,fullfile=False):
|
def get_md5(filename,fullfile=False):
|
||||||
''' returns content based hash, only first 50Mb is read, unless user wants the whole file '''
|
''' returns content based hash, only first 50Mb is read, unless user wants the whole file '''
|
||||||
if fullfile:
|
if fullfile:
|
||||||
block_size=2**20
|
anim_i=0
|
||||||
|
block_size=2**24
|
||||||
md5 = hashlib.md5()
|
md5 = hashlib.md5()
|
||||||
with open(filename,'rb') as f:
|
with open(filename,'rb') as f:
|
||||||
for chunk in iter(lambda: f.read(block_size), b''):
|
for chunk in iter(lambda: f.read(block_size), b''):
|
||||||
|
sys.stdout.write('\r'+ANIM[anim_i])
|
||||||
|
sys.stdout.flush()
|
||||||
|
anim_i=(anim_i+1)%len(ANIM)
|
||||||
md5.update(chunk)
|
md5.update(chunk)
|
||||||
|
sys.stdout.write('\r')
|
||||||
return md5.hexdigest()
|
return md5.hexdigest()
|
||||||
return hashlib.md5(open(filename,'rb').read(1024*1024*50)).hexdigest()
|
return hashlib.md5(open(filename,'rb').read(1024*1024*50)).hexdigest()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user