|
| 1 | +From 362a1ea2485ea2c49e6c250a0446bd5a33b2062c Mon Sep 17 00:00:00 2001 |
| 2 | +From: Nikita Dubrovskii < [email protected]> |
| 3 | +Date: Mon, 30 Sep 2024 15:46:31 +0200 |
| 4 | +Subject: [PATCH] org.osbuild.mkdir: support creating dirs on mounts |
| 5 | + |
| 6 | +This allows creating new directories on mounts: |
| 7 | +``` |
| 8 | +- type: org.osbuild.mkdir |
| 9 | + options: |
| 10 | + paths: |
| 11 | + - path: mount:///boot/efi |
| 12 | + devices: |
| 13 | + disk: ... |
| 14 | + mounts: |
| 15 | + - name: boot |
| 16 | + target: /boot |
| 17 | + ... |
| 18 | +``` |
| 19 | +--- |
| 20 | + stages/org.osbuild.mkdir | 22 ++++++++++++---------- |
| 21 | + stages/org.osbuild.mkdir.meta.json | 21 ++++++++++++++++++--- |
| 22 | + 2 files changed, 30 insertions(+), 13 deletions(-) |
| 23 | + |
| 24 | +diff --git a/stages/org.osbuild.mkdir b/stages/org.osbuild.mkdir |
| 25 | +index f04549f6..d2d11a7a 100755 |
| 26 | +--- a/stages/org.osbuild.mkdir |
| 27 | ++++ b/stages/org.osbuild.mkdir |
| 28 | +@@ -3,23 +3,26 @@ import os |
| 29 | + import sys |
| 30 | + |
| 31 | + import osbuild.api |
| 32 | +-from osbuild.util.path import in_tree |
| 33 | ++from osbuild.util import parsing |
| 34 | + |
| 35 | + |
| 36 | +-def main(tree, options): |
| 37 | ++def main(args): |
| 38 | ++ options = args["options"] |
| 39 | ++ |
| 40 | + for item in options["paths"]: |
| 41 | + path = item["path"] |
| 42 | + mode = item.get("mode", 0o777) |
| 43 | + parents = item.get("parents", False) |
| 44 | + exist_ok = item.get("exist_ok", False) |
| 45 | + |
| 46 | +- if not path.startswith("/"): |
| 47 | +- print("WARNING: relative path used, this is discouraged!") |
| 48 | +- |
| 49 | +- target = os.path.join(tree, path.lstrip("/")) |
| 50 | +- if not in_tree(target, tree): |
| 51 | +- raise ValueError(f"path {path} not in tree") |
| 52 | ++ if "://" not in path: |
| 53 | ++ if not path.startswith("/"): |
| 54 | ++ print("WARNING: relative path used, this is discouraged!") |
| 55 | ++ path = f"tree:///{path}" |
| 56 | ++ else: |
| 57 | ++ path = f"tree://{path}" |
| 58 | + |
| 59 | ++ target = parsing.parse_location(path, args) |
| 60 | + if parents: |
| 61 | + os.makedirs(target, mode=mode, exist_ok=exist_ok) |
| 62 | + else: |
| 63 | +@@ -33,5 +36,4 @@ def main(tree, options): |
| 64 | + |
| 65 | + |
| 66 | + if __name__ == "__main__": |
| 67 | +- args = osbuild.api.arguments() |
| 68 | +- sys.exit(main(args["tree"], args["options"])) |
| 69 | ++ sys.exit(main(osbuild.api.arguments())) |
| 70 | +diff --git a/stages/org.osbuild.mkdir.meta.json b/stages/org.osbuild.mkdir.meta.json |
| 71 | +index 5534120a..6cebaaf5 100644 |
| 72 | +--- a/stages/org.osbuild.mkdir.meta.json |
| 73 | ++++ b/stages/org.osbuild.mkdir.meta.json |
| 74 | +@@ -1,5 +1,5 @@ |
| 75 | + { |
| 76 | +- "summary": "Create directories within the tree.", |
| 77 | ++ "summary": "Create directories within the tree or mount.", |
| 78 | + "description": [ |
| 79 | + "Can create one or more directories, optionally also the", |
| 80 | + "intermediate directories. The stage can gracefully handle", |
| 81 | +@@ -31,8 +31,23 @@ |
| 82 | + ], |
| 83 | + "properties": { |
| 84 | + "path": { |
| 85 | +- "type": "string", |
| 86 | +- "pattern": "^\\/?(?!\\.\\.)((?!\\/\\.\\.\\/).)+$" |
| 87 | ++ "anyOf": [ |
| 88 | ++ { |
| 89 | ++ "type": "string", |
| 90 | ++ "description": "Target path, if a tree", |
| 91 | ++ "pattern": "^\\/?(?!\\.\\.)((?!\\/\\.\\.\\/).)+$" |
| 92 | ++ }, |
| 93 | ++ { |
| 94 | ++ "type": "string", |
| 95 | ++ "description": "Target path, if a mount", |
| 96 | ++ "pattern": "^mount://.+" |
| 97 | ++ }, |
| 98 | ++ { |
| 99 | ++ "type": "string", |
| 100 | ++ "description": "Target path, if a tree", |
| 101 | ++ "pattern": "^tree://.+" |
| 102 | ++ } |
| 103 | ++ ] |
| 104 | + }, |
| 105 | + "mode": { |
| 106 | + "type": "number", |
| 107 | +-- |
| 108 | +2.47.0 |
| 109 | + |
0 commit comments