Skip to content

Commit d72b3ee

Browse files
committed
osbuild: backport patch for mkdir
That allows making directories on mount:// targets. osbuild/osbuild#1904
1 parent ed1db27 commit d72b3ee

File tree

2 files changed

+112
-1
lines changed

2 files changed

+112
-1
lines changed

build.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ patch_osbuild() {
173173
mv /usr/bin/osbuild-mpp /usr/lib/osbuild/tools/
174174

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

178180
# And then move the files back; supermin appliance creation will need it back
179181
# in the places delivered by the RPM.
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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

Comments
 (0)