File tree Expand file tree Collapse file tree 1 file changed +2
-15
lines changed Expand file tree Collapse file tree 1 file changed +2
-15
lines changed Original file line number Diff line number Diff line change 8
8
"""
9
9
10
10
from collections import defaultdict
11
- import hashlib
12
11
import sys
13
12
14
13
from fs import open_fs
15
14
16
15
17
- def get_hash (bin_file ):
18
- """Get the md5 hash of a file."""
19
- file_hash = hashlib .md5 ()
20
- while True :
21
- chunk = bin_file .read (1024 * 1024 )
22
- if not chunk :
23
- break
24
- file_hash .update (chunk )
25
- return file_hash .hexdigest ()
26
-
27
-
28
16
hashes = defaultdict (list )
29
17
with open_fs (sys .argv [1 ]) as fs :
30
18
for path in fs .walk .files ():
31
- with fs .open (path , "rb" ) as bin_file :
32
- file_hash = get_hash (bin_file )
19
+ file_hash = fs .hash (path , "md5" )
33
20
hashes [file_hash ].append (path )
34
21
35
22
for paths in hashes .values ():
36
23
if len (paths ) > 1 :
37
24
for path in paths :
38
- print (f" { path } " )
25
+ print (path )
39
26
print ()
40
27
You can’t perform that action at this time.
0 commit comments