@@ -66,10 +66,9 @@ type Archive struct {
66
66
// BaseDirectory .
67
67
BaseDirectory string
68
68
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.
73
72
Files []string
74
73
75
74
// 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 {
114
113
return errors .New ("filesystem: archive.Filesystem is unset" )
115
114
}
116
115
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 ()), "/" )
120
124
}
121
- a .Files [ i ] = strings . TrimPrefix ( strings . TrimPrefix ( f , a . Filesystem . Path ()), "/" )
125
+ a .Files = files
122
126
}
123
127
124
128
// 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 {
128
132
compressionLevel = pgzip .NoCompression
129
133
case "best_compression" :
130
134
compressionLevel = pgzip .BestCompression
131
- case "best_speed" :
132
- fallthrough
133
135
default :
134
136
compressionLevel = pgzip .BestSpeed
135
137
}
@@ -196,6 +198,9 @@ func (a *Archive) callback(opts ...walkFunc) walkFunc {
196
198
// a non-nil error we will exit immediately.
197
199
for _ , opt := range opts {
198
200
if err := opt (dirfd , name , relative , d ); err != nil {
201
+ if err == SkipThis {
202
+ return nil
203
+ }
199
204
return err
200
205
}
201
206
}
@@ -206,6 +211,8 @@ func (a *Archive) callback(opts ...walkFunc) walkFunc {
206
211
}
207
212
}
208
213
214
+ var SkipThis = errors .New ("skip this" )
215
+
209
216
// Pushes only files defined in the Files key to the final archive.
210
217
func (a * Archive ) withFilesCallback () walkFunc {
211
218
return a .callback (func (_ int , _ , relative string , _ ufs.DirEntry ) error {
@@ -225,7 +232,7 @@ func (a *Archive) withFilesCallback() walkFunc {
225
232
return nil
226
233
}
227
234
228
- return ufs . SkipDir
235
+ return SkipThis
229
236
})
230
237
}
231
238
0 commit comments