summaryrefslogtreecommitdiffstats
path: root/meta/lib/oe/overlayfs.py
blob: b5d5e88e8047bf4c200b190ade7741b7e8b5e144 (plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#
# SPDX-License-Identifier: GPL-2.0-only
#
# This file contains common functions for overlayfs and its QA check

# this function is based on https://github.com/systemd/systemd/blob/main/src/basic/unit-name.c
def escapeSystemdUnitName(path):
    escapeMap = {
        '/': '-',
        '-': "\\x2d",
        '\\': "\\x5d"
    }
    return "".join([escapeMap.get(c, c) for c in path.strip('/')])

def strForBash(s):
    return s.replace('\\', '\\\\')

def allOverlaysUnitName(d):
    return d.getVar('PN') + '-overlays.service'

def mountUnitName(unit):
    return escapeSystemdUnitName(unit) + '.mount'

def helperUnitName(unit):
    return escapeSystemdUnitName(unit) + '-create-upper-dir.service'

def unitFileList(d):
    fileList = []
    overlayMountPoints = d.getVarFlags("OVERLAYFS_MOUNT_POINT")

    if not overlayMountPoints:
        bb.fatal("A recipe uses overlayfs class but there is no OVERLAYFS_MOUNT_POINT set in your MACHINE configuration")

    # check that we have required mount points set first
    requiredMountPoints = d.getVarFlags('OVERLAYFS_WRITABLE_PATHS')
    for mountPoint in requiredMountPoints:
        if mountPoint not in overlayMountPoints:
            bb.fatal("Missing required mount point for OVERLAYFS_MOUNT_POINT[%s] in your MACHINE configuration" % mountPoint)

    for mountPoint in overlayMountPoints:
        for path in d.getVarFlag('OVERLAYFS_WRITABLE_PATHS', mountPoint).split():
            fileList.append(mountUnitName(path))
            fileList.append(helperUnitName(path))

    fileList.append(allOverlaysUnitName(d))

    return fileList