aboutsummaryrefslogtreecommitdiff
path: root/cmd/podman/images/utils_linux.go
blob: f7c159415c1e90de4fd3a4cadc78fe7518c540f7 (plain)
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
package images

import (
	"io"
	"io/ioutil"
	"os"
	"path/filepath"

	"github.com/pkg/errors"
	"github.com/sirupsen/logrus"
	"golang.org/x/sys/unix"
)

// setupPipe for fixing https://github.com/containers/podman/issues/7017
// uses named pipe since containers/image EvalSymlinks fails with /dev/stdout
// the caller should use the returned function to clean up the pipeDir
func setupPipe() (string, func() <-chan error, error) {
	errc := make(chan error)
	pipeDir, err := ioutil.TempDir(os.TempDir(), "pipeDir")
	if err != nil {
		return "", nil, err
	}
	pipePath := filepath.Join(pipeDir, "saveio")
	err = unix.Mkfifo(pipePath, 0600)
	if err != nil {
		if e := os.RemoveAll(pipeDir); e != nil {
			logrus.Errorf("Removing named pipe: %q", e)
		}
		return "", nil, errors.Wrapf(err, "error creating named pipe")
	}
	go func() {
		fpipe, err := os.Open(pipePath)
		if err != nil {
			errc <- err
			return
		}
		_, err = io.Copy(os.Stdout, fpipe)
		fpipe.Close()
		errc <- err
	}()
	return pipePath, func() <-chan error {
		if e := os.RemoveAll(pipeDir); e != nil {
			logrus.Errorf("Removing named pipe: %q", e)
		}
		return errc
	}, nil
}