psss / rpms / libguestfs

Forked from rpms/libguestfs 5 years ago
Clone

Blame 0006-builder-Allow-upload-to-a-directory.patch

384b531
From ddf6681c75d3ca2a6e94a051a3d3650ac9f79d97 Mon Sep 17 00:00:00 2001
384b531
From: "Richard W.M. Jones" <rjones@redhat.com>
384b531
Date: Sat, 26 Oct 2013 11:27:06 +0100
384b531
Subject: [PATCH] builder: Allow --upload to a directory.
384b531
384b531
Also set the owner and permissions on the destination file correctly.
384b531
384b531
(cherry picked from commit 10c849ed1cb4375c5ef811197fa0a3206d365b86)
384b531
---
384b531
 builder/builder.ml           | 19 +++++++++++++++++--
384b531
 builder/test-virt-builder.sh |  1 +
384b531
 builder/virt-builder.pod     |  9 ++++++++-
384b531
 3 files changed, 26 insertions(+), 3 deletions(-)
384b531
384b531
diff --git a/builder/builder.ml b/builder/builder.ml
384b531
index f4f0951..dab8b41 100644
384b531
--- a/builder/builder.ml
384b531
+++ b/builder/builder.ml
384b531
@@ -592,8 +592,23 @@ exec >>%s 2>&1
384b531
   (* Upload files. *)
384b531
   List.iter (
384b531
     fun (file, dest) ->
384b531
-      msg (f_"Uploading: %s") dest;
384b531
-      g#upload file dest
384b531
+      msg (f_"Uploading: %s to %s") file dest;
384b531
+      let dest =
384b531
+        if g#is_dir dest then
384b531
+          dest ^ "/" ^ Filename.basename file
384b531
+        else
384b531
+          dest in
384b531
+      (* Do the file upload. *)
384b531
+      g#upload file dest;
384b531
+
384b531
+      (* Copy (some of) the permissions from the local file to the
384b531
+       * uploaded file.
384b531
+       *)
384b531
+      let statbuf = stat file in
384b531
+      let perms = statbuf.st_perm land 0o7777 (* sticky & set*id *) in
384b531
+      g#chmod perms dest;
384b531
+      let uid, gid = statbuf.st_uid, statbuf.st_gid in
384b531
+      g#chown uid gid dest
384b531
   ) upload;
384b531
 
384b531
   (* Edit files. *)
384b531
diff --git a/builder/test-virt-builder.sh b/builder/test-virt-builder.sh
384b531
index a5df027..b39bc3f 100755
384b531
--- a/builder/test-virt-builder.sh
384b531
+++ b/builder/test-virt-builder.sh
384b531
@@ -56,6 +56,7 @@ rm -f $output
384b531
     --root-password password:123456 \
384b531
     --mkdir /etc/foo/bar/baz \
384b531
     --upload Makefile:/Makefile \
384b531
+    --upload Makefile:/etc/foo/bar/baz \
384b531
     --delete /Makefile \
384b531
     --firstboot Makefile --firstboot-command 'echo "hello"' \
384b531
     --firstboot-install "minicom,inkscape"
384b531
diff --git a/builder/virt-builder.pod b/builder/virt-builder.pod
384b531
index 42d0d8a..810cee7 100644
384b531
--- a/builder/virt-builder.pod
384b531
+++ b/builder/virt-builder.pod
384b531
@@ -559,7 +559,14 @@ Upload local file C<FILE> to destination C<DEST> in the disk image.
384b531
 File owner and permissions from the original are preserved, so you
384b531
 should set them to what you want them to be in the disk image.
384b531
 
384b531
-See also: I<--delete>, I<--scrub>.
384b531
+C<DEST> could be the final filename.  This can be used to rename
384b531
+the file on upload.
384b531
+
384b531
+If C<DEST> is a directory name (which must already exist in the guest)
384b531
+then the file is uploaded into that directory, and it keeps the same
384b531
+name as on the local filesystem.
384b531
+
384b531
+See also: I<--mkdir>, I<--delete>, I<--scrub>.
384b531
 
384b531
 =item B<-v>
384b531
 
384b531
-- 
384b531
1.8.3.1
384b531