Previously, --no-check-md5 could still do file I/O to calculate the
md5sum of each file to allow for the hardlink and remote copy paths to
work. This wasn't intended.
Now --no-check-md5 ensures that we don't do file I/O to calculate the
md5sums, thus hardlinks and remote copying of such files won't be done
either.
... | ... |
@@ -3,10 +3,13 @@ |
3 | 3 |
## http://www.logix.cz/michal |
4 | 4 |
## License: GPL Version 2 |
5 | 5 |
|
6 |
+import logging |
|
6 | 7 |
from SortedDict import SortedDict |
7 | 8 |
import Utils |
9 |
+import Config |
|
8 | 10 |
|
9 | 11 |
zero_length_md5 = "d41d8cd98f00b204e9800998ecf8427e" |
12 |
+cfg = Config.Config() |
|
10 | 13 |
|
11 | 14 |
class FileDict(SortedDict): |
12 | 15 |
def __init__(self, mapping = {}, ignore_case = True, **kwargs): |
... | ... |
@@ -15,12 +18,14 @@ class FileDict(SortedDict): |
15 | 15 |
self.by_md5 = dict() # {md5: set(relative_files)} |
16 | 16 |
|
17 | 17 |
def record_md5(self, relative_file, md5): |
18 |
+ if md5 is None: return |
|
18 | 19 |
if md5 == zero_length_md5: return |
19 | 20 |
if md5 not in self.by_md5: |
20 | 21 |
self.by_md5[md5] = set() |
21 | 22 |
self.by_md5[md5].add(relative_file) |
22 | 23 |
|
23 | 24 |
def find_md5_one(self, md5): |
25 |
+ if md5 is None: return None |
|
24 | 26 |
try: |
25 | 27 |
return list(self.by_md5.get(md5, set()))[0] |
26 | 28 |
except: |
... | ... |
@@ -32,13 +37,15 @@ class FileDict(SortedDict): |
32 | 32 |
if 'md5' in self[relative_file]: |
33 | 33 |
return self[relative_file]['md5'] |
34 | 34 |
md5 = self.get_hardlink_md5(relative_file) |
35 |
- if md5 is None: |
|
35 |
+ if md5 is None and 'md5' in cfg.sync_checks: |
|
36 |
+ logging.debug(u"doing file I/O to read md5 of %s" % relative_file) |
|
36 | 37 |
md5 = Utils.hash_file_md5(self[relative_file]['full_name']) |
37 | 38 |
self.record_md5(relative_file, md5) |
38 | 39 |
self[relative_file]['md5'] = md5 |
39 | 40 |
return md5 |
40 | 41 |
|
41 | 42 |
def record_hardlink(self, relative_file, dev, inode, md5, size): |
43 |
+ if md5 is None: return |
|
42 | 44 |
if size == 0: return # don't record 0-length files |
43 | 45 |
if dev == 0 or inode == 0: return # Windows |
44 | 46 |
if dev not in self.hardlinks: |