Skip to content

Commit 0cfe688

Browse files
committed
fix: set correct ownership on converted rootfs file
1 parent da32a91 commit 0cfe688

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

src/rootfs.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,24 @@ fi
247247
# Unmount
248248
umount /mnt/rootfs
249249
250+
# Fix ownership to match the calling user
251+
if [ -n "$HOST_UID" ] && [ -n "$HOST_GID" ]; then
252+
chown "$HOST_UID:$HOST_GID" /output/rootfs.ext4
253+
fi
254+
250255
echo "Conversion complete"
251256
"#,
252257
size_mb = size_mb
253258
);
254259

260+
// Get the current user's UID and GID for ownership fix
261+
let uid = std::process::id();
262+
let gid = Command::new("id")
263+
.arg("-g")
264+
.output()
265+
.map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string())
266+
.unwrap_or_else(|_| uid.to_string());
267+
255268
// Get absolute paths for mounts
256269
let image_tar_abs = image_tar
257270
.canonicalize()
@@ -275,6 +288,10 @@ echo "Conversion complete"
275288
"run",
276289
"--rm",
277290
"--privileged",
291+
"-e",
292+
&format!("HOST_UID={}", uid),
293+
"-e",
294+
&format!("HOST_GID={}", gid),
278295
"-v",
279296
&format!("{}:/input/image.tar:ro", image_tar_abs.display()),
280297
"-v",

0 commit comments

Comments
 (0)