From bfd1b7cb2f4b87e7987b66a8c47069e2e06c74db Mon Sep 17 00:00:00 2001 From: Disassembler Date: Wed, 18 Dec 2019 10:12:54 +0100 Subject: [PATCH] Use cp -pr for lxchelper extract --- usr/bin/lxchelper | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) 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):