Skip to content

Commit 2931430

Browse files
committed
server(filesystem): fix archive skipping directories
Fixes pterodactyl/panel#5027 Signed-off-by: Matthew Penner <[email protected]>
1 parent 99b9924 commit 2931430

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

server/filesystem/archive.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,9 @@ type Archive struct {
6666
// BaseDirectory .
6767
BaseDirectory string
6868

69-
// Files specifies the files to archive, this takes priority over the Ignore option, if
70-
// unspecified, all files in the BasePath will be archived unless Ignore is set.
71-
//
72-
// All items in Files must be absolute within BasePath.
69+
// Files specifies the files to archive, this takes priority over the Ignore
70+
// option, if unspecified, all files in the BaseDirectory will be archived
71+
// unless Ignore is set.
7372
Files []string
7473

7574
// Progress wraps the writer of the archive to pass through the progress tracker.
@@ -114,11 +113,16 @@ func (a *Archive) Stream(ctx context.Context, w io.Writer) error {
114113
return errors.New("filesystem: archive.Filesystem is unset")
115114
}
116115

117-
for i, f := range a.Files {
118-
if !strings.HasPrefix(f, a.Filesystem.Path()) {
119-
continue
116+
if filesLen := len(a.Files); filesLen > 0 {
117+
files := make([]string, filesLen)
118+
for i, f := range a.Files {
119+
if !strings.HasPrefix(f, a.Filesystem.Path()) {
120+
files[i] = f
121+
continue
122+
}
123+
files[i] = strings.TrimPrefix(strings.TrimPrefix(f, a.Filesystem.Path()), "/")
120124
}
121-
a.Files[i] = strings.TrimPrefix(strings.TrimPrefix(f, a.Filesystem.Path()), "/")
125+
a.Files = files
122126
}
123127

124128
// Choose which compression level to use based on the compression_level configuration option
@@ -128,8 +132,6 @@ func (a *Archive) Stream(ctx context.Context, w io.Writer) error {
128132
compressionLevel = pgzip.NoCompression
129133
case "best_compression":
130134
compressionLevel = pgzip.BestCompression
131-
case "best_speed":
132-
fallthrough
133135
default:
134136
compressionLevel = pgzip.BestSpeed
135137
}
@@ -196,6 +198,9 @@ func (a *Archive) callback(opts ...walkFunc) walkFunc {
196198
// a non-nil error we will exit immediately.
197199
for _, opt := range opts {
198200
if err := opt(dirfd, name, relative, d); err != nil {
201+
if err == SkipThis {
202+
return nil
203+
}
199204
return err
200205
}
201206
}
@@ -206,6 +211,8 @@ func (a *Archive) callback(opts ...walkFunc) walkFunc {
206211
}
207212
}
208213

214+
var SkipThis = errors.New("skip this")
215+
209216
// Pushes only files defined in the Files key to the final archive.
210217
func (a *Archive) withFilesCallback() walkFunc {
211218
return a.callback(func(_ int, _, relative string, _ ufs.DirEntry) error {
@@ -225,7 +232,7 @@ func (a *Archive) withFilesCallback() walkFunc {
225232
return nil
226233
}
227234

228-
return ufs.SkipDir
235+
return SkipThis
229236
})
230237
}
231238

server/filesystem/filesystem.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ import (
2121
"github.com/pterodactyl/wings/internal/ufs"
2222
)
2323

24-
// TODO: detect and enable
25-
var useOpenat2 = true
26-
2724
type Filesystem struct {
2825
unixFS *ufs.Quota
2926

0 commit comments

Comments
 (0)