diff --git a/usr/bin/lxchelper b/usr/bin/lxchelper index c64e9ba..8fe31d2 100755 --- a/usr/bin/lxchelper +++ b/usr/bin/lxchelper @@ -3,7 +3,7 @@ import argparse import os -import shutil +import subprocess import sys import tempfile @@ -16,22 +16,13 @@ def get_layers(container): if line.startswith('lxc.hook.pre-start'): return line.split()[-1].split(',') -def copy(source, destination): - if os.path.isdir(source): - shutil.copytree(source, destination, True) - else: - shutil.copy2(source, destination) - def extract(args): with tempfile.TemporaryDirectory() as tmp_rootfs: layers = get_layers(args.container) lxcmgr.mount_rootfs(args.container, layers, tmp_rootfs) source = os.path.join(tmp_rootfs, args.source.lstrip('/')) - try: - copy(source, args.destination) - except: - lxcmgr.unmount_rootfs(tmp_rootfs) - raise + # Plain cp -pr as shutil.copytree() requires nonexistent target and copy2() doesn't retain owner + subprocess.run(['cp', '-pr', source, args.destination]) lxcmgr.unmount_rootfs(tmp_rootfs) def main(args):