blob: 27e6f921f38952b2699fa4287f7fdb4ca44c21a8 (
plain) (
blame)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 | import subprocess
import os
import shutil
class ContainerError(Exception):
    pass
def join_layers(input_paths, output_path, squashfs_path):
    if len(input_paths) == 1:
        shutil.copy2(input_paths[0], output_path)
    else:
        # We cannot use appending here as it doesn't allow replacing files
        for input_path in input_paths:
            unpack_cmd = [ os.path.join(squashfs_path, 'unsquashfs') ]
            unpack_cmd.extend([ '-f', input_path ])
            subprocess.run(unpack_cmd)
        pack_cmd = [ os.path.join(squashfs_path, 'mksquashfs') ]
        pack_cmd.append(os.path.join(os.curdir, 'squashfs-root'))
        pack_cmd.append(output_path)
        pack_cmd.append('-all-root')
        subprocess.run(pack_cmd)
        shutil.rmtree(os.path.join(os.curdir, 'squashfs-root'))
    return 0
 |