Skip to content

Commit a609ec4

Browse files
authored
Merge pull request #2224 from dmcgowan/backport-archive-gc-fixes
[release/1.0] socket in archive and gc config fixes
2 parents c0f92dd + 3d34cc0 commit a609ec4

5 files changed

Lines changed: 39 additions & 1 deletion

File tree

archive/tar.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,10 @@ func (cw *changeWriter) HandleChange(k fs.ChangeKind, p string, f os.FileInfo, e
345345
source = filepath.Join(cw.source, p)
346346
)
347347

348-
if f.Mode()&os.ModeSymlink != 0 {
348+
switch {
349+
case f.Mode()&os.ModeSocket != 0:
350+
return nil // ignore sockets
351+
case f.Mode()&os.ModeSymlink != 0:
349352
if link, err = os.Readlink(source); err != nil {
350353
return err
351354
}

archive/tar_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,22 @@ func TestDiffTar(t *testing.T) {
10061006
fstest.CreateDir("/d3/", 0755),
10071007
),
10081008
},
1009+
{
1010+
name: "IgnoreSockets",
1011+
validators: []tarEntryValidator{
1012+
fileEntry("f2", []byte("content"), 0644),
1013+
// There should be _no_ socket here, despite the fstest.CreateSocket below
1014+
fileEntry("f3", []byte("content"), 0644),
1015+
},
1016+
a: fstest.Apply(
1017+
fstest.CreateFile("/f1", []byte("content"), 0644),
1018+
),
1019+
b: fstest.Apply(
1020+
fstest.CreateFile("/f2", []byte("content"), 0644),
1021+
fstest.CreateSocket("/s0", 0644),
1022+
fstest.CreateFile("/f3", []byte("content"), 0644),
1023+
),
1024+
},
10091025
}
10101026

10111027
for _, at := range tests {

fs/fstest/file.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package fstest
22

33
import (
44
"io/ioutil"
5+
"net"
56
"os"
67
"path/filepath"
78
"time"
@@ -107,6 +108,19 @@ func Link(oldname, newname string) Applier {
107108
// }
108109
//}
109110

111+
// CreateSocket returns a file applier which creates a unix socket
112+
func CreateSocket(name string, perm os.FileMode) Applier {
113+
return applyFn(func(root string) error {
114+
fullPath := filepath.Join(root, name)
115+
ln, err := net.Listen("unix", fullPath)
116+
if err != nil {
117+
return err
118+
}
119+
defer ln.Close()
120+
return os.Chmod(fullPath, perm)
121+
})
122+
}
123+
110124
// Apply returns a new applier from the given appliers
111125
func Apply(appliers ...Applier) Applier {
112126
return applyFn(func(root string) error {

fs/fstest/testsuite.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ var (
7474
Symlink("libnothing.so", "/usr/local/lib/libnothing.so.2"),
7575
CreateDir("/home", 0755),
7676
CreateDir("/home/derek", 0700),
77+
CreateDir("/var/run/socket", 0700),
7778
)
7879

7980
// basicTest covers basic operations

gc/scheduler/scheduler.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ func (d *duration) UnmarshalText(text []byte) error {
7575
return nil
7676
}
7777

78+
func (d duration) MarshalText() (text []byte, err error) {
79+
return []byte(time.Duration(d).String()), nil
80+
}
81+
7882
func init() {
7983
plugin.Register(&plugin.Registration{
8084
Type: plugin.GCPlugin,

0 commit comments

Comments
 (0)