From 7ff15eacabd5ceafdffedb5ee20dad1b2950f49e Mon Sep 17 00:00:00 2001 From: Viktoras Kuznecovas Date: Mon, 12 Nov 2018 22:06:07 +0200 Subject: [PATCH 1/2] follow symlinks when archiving --- system/backup/archive.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/system/backup/archive.go b/system/backup/archive.go index 0a8b9644..c970abd3 100644 --- a/system/backup/archive.go +++ b/system/backup/archive.go @@ -16,6 +16,25 @@ func ArchiveFS(ctx context.Context, basedir string, w io.Writer) error { gz := gzip.NewWriter(w) tarball := tar.NewWriter(gz) + absPath, err := filepath.Abs(basedir) + if err != nil { + return err + } + + info, err := os.Lstat(absPath) + if err != nil { + return err + } + + if info.Mode()&os.ModeSymlink == os.ModeSymlink { + // This is a symlink - we need to follow it + bdir, err := os.Readlink(absPath) + if err != nil { + return err + } + basedir = bdir + } + errChan := make(chan error, 1) walkFn := func(path string, info os.FileInfo, err error) error { if err != nil { @@ -61,7 +80,7 @@ func ArchiveFS(ctx context.Context, basedir string, w io.Writer) error { } // stop processing if we get a cancellation signal - err := filepath.Walk(basedir, func(path string, info os.FileInfo, err error) error { + err = filepath.Walk(basedir, func(path string, info os.FileInfo, err error) error { go func() { errChan <- walkFn(path, info, err) }() select { From f91b4299660629cc3befbb1abcd80526a54abb1a Mon Sep 17 00:00:00 2001 From: Viktoras Kuznecovas Date: Mon, 12 Nov 2018 22:06:56 +0200 Subject: [PATCH 2/2] bubble archiving errors --- system/admin/upload/backup.go | 3 +++ system/search/backup.go | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/system/admin/upload/backup.go b/system/admin/upload/backup.go index 9dc9e315..d9bc4fb0 100644 --- a/system/admin/upload/backup.go +++ b/system/admin/upload/backup.go @@ -27,6 +27,9 @@ func Backup(ctx context.Context, res http.ResponseWriter) error { } err = backup.ArchiveFS(ctx, "uploads", f) + if err != nil { + return err + } err = f.Close() if err != nil { diff --git a/system/search/backup.go b/system/search/backup.go index 9223636f..4017b15d 100644 --- a/system/search/backup.go +++ b/system/search/backup.go @@ -26,7 +26,10 @@ func Backup(ctx context.Context, res http.ResponseWriter) error { return err } - backup.ArchiveFS(ctx, "search", f) + err = backup.ArchiveFS(ctx, "search", f) + if err != nil { + return err + } err = f.Close() if err != nil {