@@ -39,14 +39,15 @@ var snapshotPathPrefix = ""
39
39
40
40
// Snapshotter holds the root directory from which to take snapshots, and a list of snapshots taken
41
41
type Snapshotter struct {
42
- l * LayeredMap
43
- directory string
44
- ignorelist []util.IgnoreListEntry
42
+ l * LayeredMap
43
+ directory string
44
+ ignorelist []util.IgnoreListEntry
45
+ excludeRootDirTarball bool
45
46
}
46
47
47
48
// NewSnapshotter creates a new snapshotter rooted at d
48
- func NewSnapshotter (l * LayeredMap , d string ) * Snapshotter {
49
- return & Snapshotter {l : l , directory : d , ignorelist : util .IgnoreList ()}
49
+ func NewSnapshotter (l * LayeredMap , d string , excludeRootDirTarball bool ) * Snapshotter {
50
+ return & Snapshotter {l : l , directory : d , ignorelist : util .IgnoreList (), excludeRootDirTarball : excludeRootDirTarball }
50
51
}
51
52
52
53
// Init initializes a new snapshotter
@@ -114,7 +115,7 @@ func (s *Snapshotter) TakeSnapshot(files []string, shdCheckDelete bool, forceBui
114
115
115
116
t := util .NewTar (f )
116
117
defer t .Close ()
117
- if err := writeToTar (t , filesToAdd , filesToWhiteout ); err != nil {
118
+ if err := writeToTar (t , filesToAdd , filesToWhiteout , s . excludeRootDirTarball ); err != nil {
118
119
return "" , err
119
120
}
120
121
return f .Name (), nil
@@ -136,7 +137,7 @@ func (s *Snapshotter) TakeSnapshotFS() (string, error) {
136
137
return "" , err
137
138
}
138
139
139
- if err := writeToTar (t , filesToAdd , filesToWhiteOut ); err != nil {
140
+ if err := writeToTar (t , filesToAdd , filesToWhiteOut , s . excludeRootDirTarball ); err != nil {
140
141
return "" , err
141
142
}
142
143
return f .Name (), nil
@@ -230,7 +231,7 @@ func removeObsoleteWhiteouts(deletedFiles map[string]struct{}) (filesToWhiteout
230
231
return filesToWhiteout
231
232
}
232
233
233
- func writeToTar (t util.Tar , files , whiteouts []string ) error {
234
+ func writeToTar (t util.Tar , files , whiteouts []string , excludeRootDirTarball bool ) error {
234
235
timer := timing .Start ("Writing tar file" )
235
236
defer timing .DefaultRun .Stop (timer )
236
237
@@ -246,7 +247,7 @@ func writeToTar(t util.Tar, files, whiteouts []string) error {
246
247
continue
247
248
}
248
249
249
- if err := addParentDirectories (t , addedPaths , path ); err != nil {
250
+ if err := addParentDirectories (t , addedPaths , path , excludeRootDirTarball ); err != nil {
250
251
return err
251
252
}
252
253
if err := t .Whiteout (path ); err != nil {
@@ -255,12 +256,15 @@ func writeToTar(t util.Tar, files, whiteouts []string) error {
255
256
}
256
257
257
258
for _ , path := range files {
258
- if err := addParentDirectories (t , addedPaths , path ); err != nil {
259
+ if err := addParentDirectories (t , addedPaths , path , excludeRootDirTarball ); err != nil {
259
260
return err
260
261
}
261
262
if _ , pathAdded := addedPaths [path ]; pathAdded {
262
263
continue
263
264
}
265
+ if path == config .RootDir && excludeRootDirTarball {
266
+ continue
267
+ }
264
268
if err := t .AddFileToTar (path ); err != nil {
265
269
return err
266
270
}
@@ -284,11 +288,14 @@ func parentPathIncludesNonDirectory(path string) (bool, error) {
284
288
return false , nil
285
289
}
286
290
287
- func addParentDirectories (t util.Tar , addedPaths map [string ]bool , path string ) error {
291
+ func addParentDirectories (t util.Tar , addedPaths map [string ]bool , path string , excludeRootDirTarball bool ) error {
288
292
for _ , parentPath := range util .ParentDirectories (path ) {
289
293
if _ , pathAdded := addedPaths [parentPath ]; pathAdded {
290
294
continue
291
295
}
296
+ if parentPath == config .RootDir && excludeRootDirTarball {
297
+ continue
298
+ }
292
299
if err := t .AddFileToTar (parentPath ); err != nil {
293
300
return err
294
301
}
0 commit comments