The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/2291

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Closes #2290

Signed-off-by: Tycho Andersen <tycho.ander...@canonical.com>
From fa2ecdf1c528f26809ba203cf4041c162ccba001 Mon Sep 17 00:00:00 2001
From: Tycho Andersen <tycho.ander...@canonical.com>
Date: Wed, 17 Aug 2016 09:11:48 -0600
Subject: [PATCH] mkdir -p on file push

Closes #2290

Signed-off-by: Tycho Andersen <tycho.ander...@canonical.com>
---
 lxd/nsexec.go        | 12 ++++++++++++
 test/suites/basic.sh |  6 ++++++
 2 files changed, 18 insertions(+)

diff --git a/lxd/nsexec.go b/lxd/nsexec.go
index 30e2d1a..95bfe08 100644
--- a/lxd/nsexec.go
+++ b/lxd/nsexec.go
@@ -162,6 +162,18 @@ int manip_file_in_ns(char *rootfs, int pid, char *host, 
char *container, bool is
        if (is_put && stat(container, &st) < 0)
                exists = 0;
 
+       if (is_put) {
+               char *pos = strrchr(container, '/');
+               if (pos) {
+                       *pos = 0;
+                       if (mkdir_p(container, 0755) < 0) {
+                               error("failed to mkdir -p");
+                               goto close_host;
+                       }
+                       *pos = '/';
+               }
+       }
+
        umask(0);
        container_fd = open(container, container_open_flags, 0);
        if (container_fd < 0) {
diff --git a/test/suites/basic.sh b/test/suites/basic.sh
index e2696f7..1a92050 100644
--- a/test/suites/basic.sh
+++ b/test/suites/basic.sh
@@ -232,6 +232,12 @@ test_basic_usage() {
   lxc list | grep foo | grep RUNNING
   lxc stop foo --force  # stop is hanging
 
+  # check that we can put files in nonexistent directories in stopped
+  # containers
+  lxc file push /etc/hosts foo/mkdir/p/this/dir/hosts
+  lxc file pull foo/mkdir/p/this/dir/hosts "$TEST_DIR"/hosts
+  diff "$TEST_DIR"/hosts /etc/hosts
+
   # cycle it a few times
   lxc start foo
   mac1=$(lxc exec foo cat /sys/class/net/eth0/address)
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to