|
42 | 42 | from hashlib import sha1 |
43 | 43 | from pathlib import Path |
44 | 44 | from typing import List |
45 | | -from checksumdir import dirhash |
46 | 45 |
|
47 | 46 | __version__ = '1.7.4' |
48 | 47 |
|
@@ -382,6 +381,21 @@ def _abspath(self, path): |
382 | 381 | """Make relative path absolute from base dir.""" |
383 | 382 | return path if os.path.isabs(path) else os.path.join(self._basedir, path) |
384 | 383 |
|
| 384 | + def _dirhash(self, directory, hash, ignore_hidden=False, excluded_extensions=[]): |
| 385 | + assert Path(directory).is_dir() |
| 386 | + for path in sorted(Path(directory).iterdir(), key=lambda p: str(p).lower()): |
| 387 | + if path.is_file(): |
| 388 | + if not ignore_hidden and path.basename().startswith("."): |
| 389 | + continue |
| 390 | + if path.suffix in excluded_extensions: |
| 391 | + continue |
| 392 | + with open(path, "rb") as f: |
| 393 | + for chunk in iter(lambda: f.read(4096), b""): |
| 394 | + hash.update(chunk) |
| 395 | + elif path.is_dir(): |
| 396 | + hash = self._dirhash(path, hash) |
| 397 | + return hash |
| 398 | + |
385 | 399 | def _cache(func): |
386 | 400 |
|
387 | 401 | def cache(self, **kwargs): |
@@ -428,13 +442,13 @@ def cache(self, **kwargs): |
428 | 442 | # creates hash of all file content within tfdir |
429 | 443 | # excludes hidden files from being used within hash (ignores .terraform/ or .terragrunt-cache/) |
430 | 444 | # and excludes any local tfstate files |
431 | | - params["tfdir"] = dirhash( |
432 | | - self.tfdir, 'sha1', ignore_hidden=True, excluded_extensions=['backup', 'tfstate']) |
| 445 | + |
| 446 | + params["tfdir"] = self._dirhash( |
| 447 | + self.tfdir, sha1(), ignore_hidden=True, excluded_extensions=['.backup', '.tfstate']).hexdigest() |
433 | 448 |
|
434 | 449 | hash_filename = sha1( |
435 | 450 | json.dumps(params, sort_keys=True, |
436 | 451 | default=str).encode("cp037")).hexdigest() + ".pickle" |
437 | | - |
438 | 452 | cache_key = cache_dir / hash_filename |
439 | 453 | _LOGGER.debug("Cache key: %s", cache_key) |
440 | 454 |
|
|
0 commit comments