Skip to content

Commit

Permalink
Merge pull request #1116 from giuseppe/skip-sockets
Browse files Browse the repository at this point in the history
archive: skip adding sockets to the tarball
  • Loading branch information
rhatdan authored Jan 25, 2022
2 parents 8cfb9c3 + 3cd30f3 commit 43c4bb0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/archive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,10 @@ func (ta *tarAppender) addTarFile(path, name string) error {
return err
}
}
if fi.Mode()&os.ModeSocket != 0 {
logrus.Warnf("archive: skipping %q since it is a socket", path)
return nil
}

hdr, err := FileInfoHeader(name, fi, link)
if err != nil {
Expand Down
34 changes: 34 additions & 0 deletions pkg/archive/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"
"io/ioutil"
"net"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -586,6 +587,39 @@ func TestCopyFileWithTarSrcFile(t *testing.T) {
}
}

func TestCopySocket(t *testing.T) {
folder, err := ioutil.TempDir("", "storage-archive-test")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(folder)
dest := filepath.Join(folder, "dest")
src := filepath.Join(folder, "src")
err = os.MkdirAll(src, 0740)
if err != nil {
t.Fatal(err)
}

_, err = net.Listen("unix", filepath.Join(src, "unix-socket"))
if err != nil {
t.Fatal(err)
}

err = os.MkdirAll(dest, 0740)
if err != nil {
t.Fatal(err)
}
ioutil.WriteFile(src, []byte("content"), 0777)
err = defaultCopyWithTar(src, dest+"/")
if err != nil {
t.Fatalf("archiver.CopyFileWithTar shouldn't throw an error, %s.", err)
}
_, err = os.Stat(dest)
if err != nil {
t.Fatalf("Destination folder should contain the source file but did not.")
}
}

func TestTarFiles(t *testing.T) {
// TODO Windows: Figure out how to port this test.
if runtime.GOOS == windows {
Expand Down

0 comments on commit 43c4bb0

Please sign in to comment.