copy symlinks (#90)
This commit is contained in:
parent
167920c405
commit
cebb4031b3
|
|
@ -53,7 +53,7 @@ func (c *CopyCommand) ExecuteCommand(config *manifest.Schema2Config) error {
|
||||||
// For each source, iterate through each file within and copy it over
|
// For each source, iterate through each file within and copy it over
|
||||||
for src, files := range srcMap {
|
for src, files := range srcMap {
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
fi, err := os.Stat(filepath.Join(c.buildcontext, file))
|
fi, err := os.Lstat(filepath.Join(c.buildcontext, file))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -67,6 +67,17 @@ func (c *CopyCommand) ExecuteCommand(config *manifest.Schema2Config) error {
|
||||||
if err := os.MkdirAll(destPath, fi.Mode()); err != nil {
|
if err := os.MkdirAll(destPath, fi.Mode()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
} else if fi.Mode()&os.ModeSymlink != 0 {
|
||||||
|
// If file is a symlink, we want to create the same relative symlink
|
||||||
|
link, err := os.Readlink(filepath.Join(c.buildcontext, file))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
linkDst := filepath.Join(destPath, link)
|
||||||
|
if err := os.Symlink(linkDst, destPath); err != nil {
|
||||||
|
logrus.Errorf("unable to symlink %s to %s", linkDst, destPath)
|
||||||
|
return err
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// ... Else, we want to copy over a file
|
// ... Else, we want to copy over a file
|
||||||
logrus.Infof("Copying file %s to %s", file, destPath)
|
logrus.Infof("Copying file %s to %s", file, destPath)
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ func (s *Snapshotter) TakeSnapshotOfFiles(files []string) ([]byte, error) {
|
||||||
w := tar.NewWriter(buf)
|
w := tar.NewWriter(buf)
|
||||||
defer w.Close()
|
defer w.Close()
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
info, err := os.Stat(file)
|
info, err := os.Lstat(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -142,11 +142,11 @@ func IsDestDir(path string) bool {
|
||||||
// Assume dest is also a dir, and copy to dest/relpath
|
// Assume dest is also a dir, and copy to dest/relpath
|
||||||
// If dest is not an absolute filepath, add /cwd to the beginning
|
// If dest is not an absolute filepath, add /cwd to the beginning
|
||||||
func DestinationFilepath(filename, srcName, dest, cwd, buildcontext string) (string, error) {
|
func DestinationFilepath(filename, srcName, dest, cwd, buildcontext string) (string, error) {
|
||||||
fi, err := os.Stat(filepath.Join(buildcontext, filename))
|
fi, err := os.Lstat(filepath.Join(buildcontext, filename))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
src, err := os.Stat(filepath.Join(buildcontext, srcName))
|
src, err := os.Lstat(filepath.Join(buildcontext, srcName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ func Files(root string) ([]string, error) {
|
||||||
|
|
||||||
// FilepathExists returns true if the path exists
|
// FilepathExists returns true if the path exists
|
||||||
func FilepathExists(path string) bool {
|
func FilepathExists(path string) bool {
|
||||||
_, err := os.Stat(path)
|
_, err := os.Lstat(path)
|
||||||
return !os.IsNotExist(err)
|
return !os.IsNotExist(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -145,7 +145,7 @@ func FilepathExists(path string) bool {
|
||||||
func CreateFile(path string, reader io.Reader, perm os.FileMode) error {
|
func CreateFile(path string, reader io.Reader, perm os.FileMode) error {
|
||||||
// Create directory path if it doesn't exist
|
// Create directory path if it doesn't exist
|
||||||
baseDir := filepath.Dir(path)
|
baseDir := filepath.Dir(path)
|
||||||
if _, err := os.Stat(baseDir); os.IsNotExist(err) {
|
if _, err := os.Lstat(baseDir); os.IsNotExist(err) {
|
||||||
logrus.Debugf("baseDir %s for file %s does not exist. Creating.", baseDir, path)
|
logrus.Debugf("baseDir %s for file %s does not exist. Creating.", baseDir, path)
|
||||||
if err := os.MkdirAll(baseDir, 0755); err != nil {
|
if err := os.MkdirAll(baseDir, 0755); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -148,7 +148,7 @@ func fileIsUncompressedTar(src string) bool {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
fi, err := os.Stat(src)
|
fi, err := os.Lstat(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue