[lxc-devel] [lxd/master] GET of a nonexistent file 404s
tych0 on Github
lxc-bot at linuxcontainers.org
Tue May 31 16:25:24 UTC 2016
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 377 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160531/18935f11/attachment.bin>
-------------- next part --------------
From c11058ef81ee109cb82a6ea0cc70a5b32949bea4 Mon Sep 17 00:00:00 2001
From: Tycho Andersen <tycho.andersen at canonical.com>
Date: Tue, 31 May 2016 09:55:40 -0600
Subject: [PATCH] GET of a nonexistent file 404s
Closes #2059
Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
lxd/container_file.go | 2 +-
lxd/container_lxc.go | 3 +++
test/suites/filemanip.sh | 5 +++++
3 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/lxd/container_file.go b/lxd/container_file.go
index 06590a5..7ac2085 100644
--- a/lxd/container_file.go
+++ b/lxd/container_file.go
@@ -52,7 +52,7 @@ func containerFileGet(c container, path string, r *http.Request) Response {
// Pul the file from the container
uid, gid, mode, err := c.FilePull(path, temp.Name())
if err != nil {
- return InternalError(err)
+ return SmartError(err)
}
headers := map[string]string{
diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 6aa3510..e07d974 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -2886,6 +2886,9 @@ func (c *containerLXC) FilePull(srcpath string, dstpath string) (int, int, os.Fi
// Extract errors
if strings.HasPrefix(line, "error: ") {
+ if strings.HasSuffix(line, "No such file or directory") {
+ return -1, -1, 0, os.ErrNotExist
+ }
return -1, -1, 0, fmt.Errorf(strings.TrimPrefix(line, "error: "))
}
diff --git a/test/suites/filemanip.sh b/test/suites/filemanip.sh
index f4b7b05..07ca148 100644
--- a/test/suites/filemanip.sh
+++ b/test/suites/filemanip.sh
@@ -2,6 +2,7 @@
test_filemanip() {
ensure_import_testimage
+ ensure_has_localhost_remote "${LXD_ADDR}"
lxc launch testimage filemanip
lxc exec filemanip -- ln -s /tmp/ /tmp/outside
@@ -10,5 +11,9 @@ test_filemanip() {
[ ! -f /tmp/main.sh ]
lxc exec filemanip -- ls /tmp/main.sh
+ # missing files should return 404
+ err=$(my_curl -o /dev/null -w "%{http_code}" -X GET "https://${LXD_ADDR}/1.0/containers/filemanip/files?path=/tmp/foo")
+ [ "${err}" -eq "404" ]
+
lxc delete filemanip -f
}
More information about the lxc-devel
mailing list