-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaufstarfilter.go
More file actions
59 lines (50 loc) · 1.42 KB
/
aufstarfilter.go
File metadata and controls
59 lines (50 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package tarutil
import (
"archive/tar"
"fmt"
"os"
"path/filepath"
)
// AUFSWhiteouts is a TarFilter to convert overlay whiteouts to aufs whiteouts.
type AUFSWhiteouts struct {
previousEntry *tar.Header
tw *tar.Writer
}
// NewAUFSWhiteouts creates a new overlay whiteout filter.
func NewAUFSWhiteouts() *AUFSWhiteouts {
return &AUFSWhiteouts{}
}
// SetTarWriter sets the tar writer for output processing.
func (o *AUFSWhiteouts) SetTarWriter(tw *tar.Writer) error {
if o.tw == nil {
o.tw = tw
return nil
}
return fmt.Errorf("the TarWriter is already set")
}
// Close closes the tar filter, finalizing any processing.
func (o *AUFSWhiteouts) Close() error {
return o.tw.Close()
}
// HandleEntry is the meat and potatoes of the filter; managing the overlay files.
func (o *AUFSWhiteouts) HandleEntry(h *tar.Header) (bool, bool, error) {
fi := h.FileInfo()
if fi.Mode()&os.ModeCharDevice != 0 && h.Devmajor == 0 && h.Devminor == 0 {
dir, filename := filepath.Split(h.Name)
h.Name = filepath.Join(dir, whiteoutPrefix+filename)
h.Typeflag = tar.TypeReg
h.Size = 0
return false, true, nil
}
if fi.Mode()&os.ModeDir != 0 {
opaque, ok := h.Xattrs[overlayOpaqueXattr]
if ok && opaque == overlayOpaqueXattrValue {
delete(h.Xattrs, overlayOpaqueXattr)
h.Typeflag = tar.TypeReg
h.Name = filepath.Join(h.Name, whiteoutOpaqueDir)
h.Size = 0
}
return false, true, nil
}
return true, true, nil
}