Skip to content

Commit

Permalink
follow symlinks when archiving
Browse files Browse the repository at this point in the history
  • Loading branch information
vkuznecovas authored and nilslice committed Jan 1, 2019
1 parent 222b13a commit 7ff15ea
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion system/backup/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 7ff15ea

Please sign in to comment.