forked from mirrors/nixpkgs
stream_layered_image: Use pathlib module for directory traversal
This commit is contained in:
parent
16199521ea
commit
fa8f2bf34f
|
@ -37,8 +37,8 @@ import re
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import pathlib
|
||||||
import tarfile
|
import tarfile
|
||||||
import itertools
|
|
||||||
import threading
|
import threading
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
@ -90,18 +90,17 @@ def archive_paths_to(obj, paths, mtime, add_nix, filter=None):
|
||||||
ti = tar.gettarinfo(os.path.join("/", path))
|
ti = tar.gettarinfo(os.path.join("/", path))
|
||||||
tar.addfile(apply_filters(append_root(ti)))
|
tar.addfile(apply_filters(append_root(ti)))
|
||||||
|
|
||||||
for root, dirs, files in os.walk(path, topdown=True):
|
for filename in pathlib.Path(path).rglob("*"):
|
||||||
for name in itertools.chain(dirs, files):
|
ti = append_root(tar.gettarinfo(filename))
|
||||||
name = os.path.join(root, name)
|
|
||||||
ti = append_root(tar.gettarinfo(name))
|
|
||||||
|
|
||||||
# copy hardlinks as regular files
|
# copy hardlinks as regular files
|
||||||
if ti.islnk():
|
if ti.islnk():
|
||||||
ti.type = tarfile.REGTYPE
|
ti.type = tarfile.REGTYPE
|
||||||
|
ti.linkname = ""
|
||||||
|
|
||||||
ti = apply_filters(ti)
|
ti = apply_filters(ti)
|
||||||
if ti.isfile():
|
if ti.isfile():
|
||||||
with open(name, "rb") as f:
|
with open(filename, "rb") as f:
|
||||||
tar.addfile(ti, f)
|
tar.addfile(ti, f)
|
||||||
else:
|
else:
|
||||||
tar.addfile(ti)
|
tar.addfile(ti)
|
||||||
|
|
Loading…
Reference in a new issue