mirror of
https://github.com/octoleo/restic.git
synced 2024-12-22 10:58:55 +00:00
in tar dump, convert uid, gid of value -1 to zero
This commit is contained in:
parent
90fb6f70b4
commit
10fa5cde0a
12
changelog/unreleased/issue-4103
Normal file
12
changelog/unreleased/issue-4103
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
Bugfix: fix restic dump of tar file with 32-bit binary
|
||||||
|
|
||||||
|
In restic up to 0.14.0, the restic dump from a 32-bit binary of a
|
||||||
|
snapshot of standard input that was created in Windows has as a
|
||||||
|
result a tar file whose content has a negative uid and gid. As a
|
||||||
|
result, gnu tar exits with failure status whenever it tries to
|
||||||
|
access such a tar file. With this fix, the tar file that is now
|
||||||
|
dumped from a 32-bit binary has content with non-negative uid and
|
||||||
|
gid.
|
||||||
|
|
||||||
|
https://github.com/restic/restic/issues/4103
|
||||||
|
https://github.com/restic/restic/pull/4104
|
@ -3,6 +3,7 @@ package dump
|
|||||||
import (
|
import (
|
||||||
"archive/tar"
|
"archive/tar"
|
||||||
"context"
|
"context"
|
||||||
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@ -38,6 +39,14 @@ const (
|
|||||||
cISVTX = 0o1000 // Save text (sticky bit)
|
cISVTX = 0o1000 // Save text (sticky bit)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// substitute a uid or gid of -1 (which is converted to 2^32 - 1) with zero
|
||||||
|
func tarId(id uint32) int {
|
||||||
|
if id == math.MaxUint32 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return int(id)
|
||||||
|
}
|
||||||
|
|
||||||
func (d *Dumper) dumpNodeTar(ctx context.Context, node *restic.Node, w *tar.Writer) error {
|
func (d *Dumper) dumpNodeTar(ctx context.Context, node *restic.Node, w *tar.Writer) error {
|
||||||
relPath, err := filepath.Rel("/", node.Path)
|
relPath, err := filepath.Rel("/", node.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -48,8 +57,8 @@ func (d *Dumper) dumpNodeTar(ctx context.Context, node *restic.Node, w *tar.Writ
|
|||||||
Name: filepath.ToSlash(relPath),
|
Name: filepath.ToSlash(relPath),
|
||||||
Size: int64(node.Size),
|
Size: int64(node.Size),
|
||||||
Mode: int64(node.Mode.Perm()), // cIS* constants are added later
|
Mode: int64(node.Mode.Perm()), // cIS* constants are added later
|
||||||
Uid: int(node.UID),
|
Uid: tarId(node.UID),
|
||||||
Gid: int(node.GID),
|
Gid: tarId(node.GID),
|
||||||
Uname: node.User,
|
Uname: node.User,
|
||||||
Gname: node.Group,
|
Gname: node.Group,
|
||||||
ModTime: node.ModTime,
|
ModTime: node.ModTime,
|
||||||
|
Loading…
Reference in New Issue
Block a user