From 80a11960dd37b86ecf1d5c10c4f4ef28f5a80c00 Mon Sep 17 00:00:00 2001 From: Simon Beck Date: Tue, 21 May 2019 20:48:45 +0200 Subject: [PATCH] dump: Always dump relative paths into tarballs Tarballs should only contain relative paths. --- internal/dump/tar.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/dump/tar.go b/internal/dump/tar.go index efb646a0a..5d3a10f53 100644 --- a/internal/dump/tar.go +++ b/internal/dump/tar.go @@ -5,6 +5,7 @@ import ( "context" "io" "path" + "path/filepath" "strings" "github.com/restic/restic/internal/errors" @@ -65,8 +66,13 @@ func tarTree(ctx context.Context, repo restic.Repository, rootNode *restic.Node, } func tarNode(ctx context.Context, tw *tar.Writer, node *restic.Node, repo restic.Repository) error { + relPath, err := filepath.Rel("/", node.Path) + if err != nil { + return err + } + header := &tar.Header{ - Name: node.Path, + Name: relPath, Size: int64(node.Size), Mode: int64(node.Mode), Uid: int(node.UID), @@ -86,7 +92,7 @@ func tarNode(ctx context.Context, tw *tar.Writer, node *restic.Node, repo restic header.Typeflag = tar.TypeDir } - err := tw.WriteHeader(header) + err = tw.WriteHeader(header) if err != nil { return errors.Wrap(err, "TarHeader ")