Skip to content

Commit

Permalink
osbuild: backport patch for mkdir
Browse files Browse the repository at this point in the history
That allows making directories on mount:// targets.
osbuild/osbuild#1904
  • Loading branch information
dustymabe committed Nov 4, 2024
1 parent ed1db27 commit d72b3ee
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 1 deletion.
4 changes: 3 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ patch_osbuild() {
mv /usr/bin/osbuild-mpp /usr/lib/osbuild/tools/

# Now all the software is under the /usr/lib/osbuild dir and we can patch
patch -d /usr/lib/osbuild -p1 < /usr/lib/coreos-assembler/0001-hacks-for-coreos-selinux-issues.patch
cat /usr/lib/coreos-assembler/0001-hacks-for-coreos-selinux-issues.patch \
/usr/lib/coreos-assembler/0001-org.osbuild.mkdir-support-creating-dirs-on-mounts.patch \
| patch -d /usr/lib/osbuild -p1

# And then move the files back; supermin appliance creation will need it back
# in the places delivered by the RPM.
Expand Down
109 changes: 109 additions & 0 deletions src/0001-org.osbuild.mkdir-support-creating-dirs-on-mounts.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
From 362a1ea2485ea2c49e6c250a0446bd5a33b2062c Mon Sep 17 00:00:00 2001
From: Nikita Dubrovskii <[email protected]>
Date: Mon, 30 Sep 2024 15:46:31 +0200
Subject: [PATCH] org.osbuild.mkdir: support creating dirs on mounts

This allows creating new directories on mounts:
```
- type: org.osbuild.mkdir
options:
paths:
- path: mount:///boot/efi
devices:
disk: ...
mounts:
- name: boot
target: /boot
...
```
---
stages/org.osbuild.mkdir | 22 ++++++++++++----------
stages/org.osbuild.mkdir.meta.json | 21 ++++++++++++++++++---
2 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/stages/org.osbuild.mkdir b/stages/org.osbuild.mkdir
index f04549f6..d2d11a7a 100755
--- a/stages/org.osbuild.mkdir
+++ b/stages/org.osbuild.mkdir
@@ -3,23 +3,26 @@ import os
import sys

import osbuild.api
-from osbuild.util.path import in_tree
+from osbuild.util import parsing


-def main(tree, options):
+def main(args):
+ options = args["options"]
+
for item in options["paths"]:
path = item["path"]
mode = item.get("mode", 0o777)
parents = item.get("parents", False)
exist_ok = item.get("exist_ok", False)

- if not path.startswith("/"):
- print("WARNING: relative path used, this is discouraged!")
-
- target = os.path.join(tree, path.lstrip("/"))
- if not in_tree(target, tree):
- raise ValueError(f"path {path} not in tree")
+ if "://" not in path:
+ if not path.startswith("/"):
+ print("WARNING: relative path used, this is discouraged!")
+ path = f"tree:///{path}"
+ else:
+ path = f"tree://{path}"

+ target = parsing.parse_location(path, args)
if parents:
os.makedirs(target, mode=mode, exist_ok=exist_ok)
else:
@@ -33,5 +36,4 @@ def main(tree, options):


if __name__ == "__main__":
- args = osbuild.api.arguments()
- sys.exit(main(args["tree"], args["options"]))
+ sys.exit(main(osbuild.api.arguments()))
diff --git a/stages/org.osbuild.mkdir.meta.json b/stages/org.osbuild.mkdir.meta.json
index 5534120a..6cebaaf5 100644
--- a/stages/org.osbuild.mkdir.meta.json
+++ b/stages/org.osbuild.mkdir.meta.json
@@ -1,5 +1,5 @@
{
- "summary": "Create directories within the tree.",
+ "summary": "Create directories within the tree or mount.",
"description": [
"Can create one or more directories, optionally also the",
"intermediate directories. The stage can gracefully handle",
@@ -31,8 +31,23 @@
],
"properties": {
"path": {
- "type": "string",
- "pattern": "^\\/?(?!\\.\\.)((?!\\/\\.\\.\\/).)+$"
+ "anyOf": [
+ {
+ "type": "string",
+ "description": "Target path, if a tree",
+ "pattern": "^\\/?(?!\\.\\.)((?!\\/\\.\\.\\/).)+$"
+ },
+ {
+ "type": "string",
+ "description": "Target path, if a mount",
+ "pattern": "^mount://.+"
+ },
+ {
+ "type": "string",
+ "description": "Target path, if a tree",
+ "pattern": "^tree://.+"
+ }
+ ]
},
"mode": {
"type": "number",
--
2.47.0

0 comments on commit d72b3ee

Please sign in to comment.