@@ -115,25 +115,32 @@ def put(self, original, converted):
115
115
def _get_file_hash (self , path , block_size = 2 ** 20 ):
116
116
if path in self .hash_cache :
117
117
return self .hash_cache [path ]
118
+ _ , ext = os .path .splitext (path )
119
+ version_tag = self .converter_version .get (ext )
120
+ if version_tag is None :
121
+ warnings .warn (
122
+ ("Don't know the external converter for files with extension "
123
+ "%s, cannot ensure cache invalidation on version update." )
124
+ % ext )
125
+ result = self ._get_file_hash_static (path , block_size , version_tag )
126
+ self .hash_cache [path ] = result
127
+ return result
128
+
129
+ @staticmethod
130
+ def _get_file_hash_static (path , block_size , version_tag ):
131
+ # the parts of _get_file_hash that are called from the deprecated
132
+ # compare.get_file_hash; can merge into _get_file_hash once that
133
+ # function is removed
118
134
md5 = hashlib .md5 ()
119
135
with open (path , 'rb' ) as fd :
120
136
while True :
121
137
data = fd .read (block_size )
122
138
if not data :
123
139
break
124
140
md5 .update (data )
125
- _ , ext = os .path .splitext (path )
126
- version_tag = self .converter_version .get (ext )
127
- if version_tag :
141
+ if version_tag is not None :
128
142
md5 .update (version_tag )
129
- else :
130
- warnings .warn (("Don't know the external converter for %s, cannot "
131
- "ensure cache invalidation on version update." )
132
- % path )
133
-
134
- result = md5 .hexdigest ()
135
- self .hash_cache [path ] = result
136
- return result
143
+ return md5 .hexdigest ()
137
144
138
145
def report (self ):
139
146
"""Return information about the cache.
0 commit comments