server(fs): keep file mode when extracting archive

This commit is contained in:
Matthew Penner
2021-07-15 15:37:38 -06:00
parent f422081695
commit 31ff3f8b56
5 changed files with 23 additions and 10 deletions

View File

@@ -5,14 +5,16 @@ import (
"crypto/sha1"
"encoding/hex"
"io"
"io/fs"
"os"
"path"
"emperror.dev/errors"
"github.com/apex/log"
"golang.org/x/sync/errgroup"
"github.com/pterodactyl/wings/config"
"github.com/pterodactyl/wings/remote"
"golang.org/x/sync/errgroup"
)
type AdapterType string
@@ -24,7 +26,7 @@ const (
// RestoreCallback is a generic restoration callback that exists for both local
// and remote backups allowing the files to be restored.
type RestoreCallback func(file string, r io.Reader) error
type RestoreCallback func(file string, r io.Reader, mode fs.FileMode) error
// noinspection GoNameStartsWithPackageName
type BackupInterface interface {

View File

@@ -6,9 +6,11 @@ import (
"os"
"emperror.dev/errors"
"github.com/pterodactyl/wings/server/filesystem"
"github.com/mholt/archiver/v3"
"github.com/pterodactyl/wings/remote"
)
@@ -85,12 +87,10 @@ func (b *LocalBackup) Restore(ctx context.Context, _ io.Reader, callback Restore
// Stop walking if the context is canceled.
return archiver.ErrStopWalk
default:
{
if f.IsDir() {
return nil
}
return callback(filesystem.ExtractNameFromArchive(f), f)
if f.IsDir() {
return nil
}
return callback(filesystem.ExtractNameFromArchive(f), f, f.Mode())
}
})
}

View File

@@ -13,9 +13,11 @@ import (
"emperror.dev/errors"
"github.com/cenkalti/backoff/v4"
"github.com/pterodactyl/wings/server/filesystem"
"github.com/juju/ratelimit"
"github.com/pterodactyl/wings/config"
"github.com/pterodactyl/wings/remote"
)
@@ -114,7 +116,7 @@ func (s *S3Backup) Restore(ctx context.Context, r io.Reader, callback RestoreCal
return err
}
if header.Typeflag == tar.TypeReg {
if err := callback(header.Name, tr); err != nil {
if err := callback(header.Name, tr, header.FileInfo().Mode()); err != nil {
return err
}
}