Permalink
Browse files

Merge pull request #292 from ponzu-cms/ponzu-dev

backup: follow symlinks when archiving
  • Loading branch information...
nilslice committed Jan 1, 2019
2 parents 222b13a + f91b429 commit 584a06456960231eed5171948dcc604980289e42
Showing with 27 additions and 2 deletions.
  1. +3 −0 system/admin/upload/backup.go
  2. +20 −1 system/backup/archive.go
  3. +4 −1 system/search/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 {
@@ -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 {
@@ -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 {

0 comments on commit 584a064

Please sign in to comment.