diff options
author | Utku Demir <me@utdemir.com> | 2020-06-22 15:11:04 +1200 |
---|---|---|
committer | Utku Demir <me@utdemir.com> | 2020-06-22 15:11:04 +1200 |
commit | fa8f2bf34f3f065571670c59217f877a73868f8f (patch) | |
tree | b6c4dde900fd65df843b939ee8f5cba6a49b689d /pkgs/build-support | |
parent | 16199521eaaf5d31952c19e44bcca205959df57f (diff) |
stream_layered_image: Use pathlib module for directory traversal
Diffstat (limited to 'pkgs/build-support')
-rw-r--r-- | pkgs/build-support/docker/stream_layered_image.py | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/pkgs/build-support/docker/stream_layered_image.py b/pkgs/build-support/docker/stream_layered_image.py index a9de10f9efaa1..4348513338d72 100644 --- a/pkgs/build-support/docker/stream_layered_image.py +++ b/pkgs/build-support/docker/stream_layered_image.py @@ -37,8 +37,8 @@ import re import sys import json import hashlib +import pathlib import tarfile -import itertools import threading from datetime import datetime from collections import namedtuple @@ -90,21 +90,20 @@ def archive_paths_to(obj, paths, mtime, add_nix, filter=None): ti = tar.gettarinfo(os.path.join("/", path)) tar.addfile(apply_filters(append_root(ti))) - for root, dirs, files in os.walk(path, topdown=True): - for name in itertools.chain(dirs, files): - name = os.path.join(root, name) - ti = append_root(tar.gettarinfo(name)) - - # copy hardlinks as regular files - if ti.islnk(): - ti.type = tarfile.REGTYPE - - ti = apply_filters(ti) - if ti.isfile(): - with open(name, "rb") as f: - tar.addfile(ti, f) - else: - tar.addfile(ti) + for filename in pathlib.Path(path).rglob("*"): + ti = append_root(tar.gettarinfo(filename)) + + # copy hardlinks as regular files + if ti.islnk(): + ti.type = tarfile.REGTYPE + ti.linkname = "" + + ti = apply_filters(ti) + if ti.isfile(): + with open(filename, "rb") as f: + tar.addfile(ti, f) + else: + tar.addfile(ti) class ExtractChecksum: |