summaryrefslogtreecommitdiff
path: root/system/backup/archive.go
diff options
context:
space:
mode:
authorSteve Manuel <nilslice@gmail.com>2019-01-01 17:07:04 -0600
committerGitHub <noreply@github.com>2019-01-01 17:07:04 -0600
commit584a06456960231eed5171948dcc604980289e42 (patch)
treeeeb25f29f2de528367e6549304a7ad36a063f841 /system/backup/archive.go
parent222b13ae9181160e610fa7afa738f1900e6fa374 (diff)
parentf91b4299660629cc3befbb1abcd80526a54abb1a (diff)
Merge pull request #292 from ponzu-cms/ponzu-dev
backup: follow symlinks when archiving
Diffstat (limited to 'system/backup/archive.go')
-rw-r--r--system/backup/archive.go21
1 files changed, 20 insertions, 1 deletions
diff --git a/system/backup/archive.go b/system/backup/archive.go
index 0a8b964..c970abd 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 {