Use cp -pr for lxchelper extract
This commit is contained in:
parent
e57cfc493a
commit
bfd1b7cb2f
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user