github.com/endocode/docker@v1.4.2-0.20160113120958-46eb4700391e/daemon/execdriver/native/tmpfs.go (about)

     1  package native
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"os/exec"
     7  	"strings"
     8  
     9  	"github.com/Sirupsen/logrus"
    10  	"github.com/opencontainers/runc/libcontainer/configs"
    11  )
    12  
    13  func genTmpfsPremountCmd(tmpDir string, fullDest string, dest string) []configs.Command {
    14  	var premount []configs.Command
    15  	tarPath, err := exec.LookPath("tar")
    16  	if err != nil {
    17  		logrus.Warn("tar command is not available for tmpfs mount: %s", err)
    18  		return premount
    19  	}
    20  	if _, err = exec.LookPath("rm"); err != nil {
    21  		logrus.Warn("rm command is not available for tmpfs mount: %s", err)
    22  		return premount
    23  	}
    24  	tarFile := fmt.Sprintf("%s/%s.tar", tmpDir, strings.Replace(dest, "/", "_", -1))
    25  	if _, err := os.Stat(fullDest); err == nil {
    26  		premount = append(premount, configs.Command{
    27  			Path: tarPath,
    28  			Args: []string{"-cf", tarFile, "-C", fullDest, "."},
    29  		})
    30  	}
    31  	return premount
    32  }
    33  
    34  func genTmpfsPostmountCmd(tmpDir string, fullDest string, dest string) []configs.Command {
    35  	var postmount []configs.Command
    36  	tarPath, err := exec.LookPath("tar")
    37  	if err != nil {
    38  		return postmount
    39  	}
    40  	rmPath, err := exec.LookPath("rm")
    41  	if err != nil {
    42  		return postmount
    43  	}
    44  	if _, err := os.Stat(fullDest); os.IsNotExist(err) {
    45  		return postmount
    46  	}
    47  	tarFile := fmt.Sprintf("%s/%s.tar", tmpDir, strings.Replace(dest, "/", "_", -1))
    48  	postmount = append(postmount, configs.Command{
    49  		Path: tarPath,
    50  		Args: []string{"-xf", tarFile, "-C", fullDest, "."},
    51  	})
    52  	return append(postmount, configs.Command{
    53  		Path: rmPath,
    54  		Args: []string{"-f", tarFile},
    55  	})
    56  }