Use cp -pr for lxchelper extract
This commit is contained in:
parent
e57cfc493a
commit
bfd1b7cb2f
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
import shutil
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
@ -16,22 +16,13 @@ def get_layers(container):
|
|||||||
if line.startswith('lxc.hook.pre-start'):
|
if line.startswith('lxc.hook.pre-start'):
|
||||||
return line.split()[-1].split(',')
|
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):
|
def extract(args):
|
||||||
with tempfile.TemporaryDirectory() as tmp_rootfs:
|
with tempfile.TemporaryDirectory() as tmp_rootfs:
|
||||||
layers = get_layers(args.container)
|
layers = get_layers(args.container)
|
||||||
lxcmgr.mount_rootfs(args.container, layers, tmp_rootfs)
|
lxcmgr.mount_rootfs(args.container, layers, tmp_rootfs)
|
||||||
source = os.path.join(tmp_rootfs, args.source.lstrip('/'))
|
source = os.path.join(tmp_rootfs, args.source.lstrip('/'))
|
||||||
try:
|
# Plain cp -pr as shutil.copytree() requires nonexistent target and copy2() doesn't retain owner
|
||||||
copy(source, args.destination)
|
subprocess.run(['cp', '-pr', source, args.destination])
|
||||||
except:
|
|
||||||
lxcmgr.unmount_rootfs(tmp_rootfs)
|
|
||||||
raise
|
|
||||||
lxcmgr.unmount_rootfs(tmp_rootfs)
|
lxcmgr.unmount_rootfs(tmp_rootfs)
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
|
Loading…
Reference in New Issue
Block a user