Skip to content

Commit 0c1a5c4

Browse files
author
Daniel van Gils
committed
remove using stat for permission, the permission copying is handled by docker. #8
1 parent 7e015e4 commit 0c1a5c4

File tree

1 file changed

+2
-73
lines changed

1 file changed

+2
-73
lines changed

build/builder.go

+2-73
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"path"
1414
"path/filepath"
1515
"regexp"
16-
"strconv"
1716
"strings"
1817
"sync"
1918

@@ -404,60 +403,9 @@ func (b *Builder) BuildStep(step *Step, step_number int) error {
404403
}
405404

406405
if len(step.Artifacts) > 0 {
407-
b.Conf.Logger.Noticef("Starting container %s to fetch artifact permissions", container.ID)
408-
startOpts := &docker.HostConfig{}
409-
err := b.docker.StartContainer(container.ID, startOpts)
410-
if err != nil {
411-
return err
412-
}
413-
414-
permMap := make(map[string]int)
415-
416-
for _, art := range step.Artifacts {
417-
execOpts := docker.CreateExecOptions{
418-
Container: container.ID,
419-
AttachStdin: false,
420-
AttachStdout: true,
421-
AttachStderr: true,
422-
Tty: false,
423-
Cmd: []string{"stat", "--format='%a'", art.Source},
424-
}
425-
execObj, err := b.docker.CreateExec(execOpts)
426-
if err != nil {
427-
return err
428-
}
429-
430-
buf := new(bytes.Buffer)
431-
startExecOpts := docker.StartExecOptions{
432-
OutputStream: buf,
433-
ErrorStream: os.Stderr,
434-
RawTerminal: false,
435-
Detach: false,
436-
}
437-
438-
if err := b.docker.StartExec(execObj.ID, startExecOpts); err != nil {
439-
b.Conf.Logger.Errorf("Failed to fetch artifact permissions for %s: %s", art.Source, err.Error())
440-
}
441-
442-
permsString := strings.Replace(strings.Replace(buf.String(), "'", "", -1), "\n", "", -1)
443-
perms, err := strconv.Atoi(permsString)
444-
if err != nil {
445-
b.Conf.Logger.Errorf("Failed to fetch artifact permissions for %s: %s", art.Source, err.Error())
446-
}
447-
permMap[art.Source] = perms
448-
b.Conf.Logger.Debugf("Permissions for %s is %d", art.Source, perms)
449-
}
450-
451-
b.Conf.Logger.Debugf("Stopping the container %s", container.ID)
452-
err = b.docker.StopContainer(container.ID, 0)
453-
if err != nil {
454-
return err
455-
}
456-
457406
b.Conf.Logger.Noticef("Copying artifacts from %s", container.ID)
458-
459407
for _, art := range step.Artifacts {
460-
err = b.copyToHost(&art, container.ID, permMap)
408+
err = b.copyToHost(&art, container.ID)
461409
if err != nil {
462410
return err
463411
}
@@ -595,18 +543,7 @@ func (b *Builder) replaceFromField(step *Step, step_number int) error {
595543
return nil
596544
}
597545

598-
func overwrite(mpath string) (*os.File, error) {
599-
f, err := os.OpenFile(mpath, os.O_RDWR|os.O_TRUNC, 0777)
600-
if err != nil {
601-
f, err = os.Create(mpath)
602-
if err != nil {
603-
return f, err
604-
}
605-
}
606-
return f, nil
607-
}
608-
609-
func (b *Builder) copyToHost(a *Artifact, container string, perms map[string]int) error {
546+
func (b *Builder) copyToHost(a *Artifact, container string) error {
610547
// create the artifacts distination folder if not there
611548
destPath := path.Join(b.Conf.Workdir, a.Dest)
612549
err := os.MkdirAll(destPath, 0777)
@@ -658,15 +595,7 @@ func (b *Builder) copyToHost(a *Artifact, container string, perms map[string]int
658595
default:
659596
return errors.New("Invalid header type")
660597
}
661-
662-
b.Conf.Logger.Debugf("Setting file permissions for %s to %d", destFile, perms[a.Source])
663-
err = os.Chmod(destFile, os.FileMode(perms[a.Source])|0700)
664-
if err != nil {
665-
return err
666-
}
667-
668598
}
669-
670599
return nil
671600
}
672601

0 commit comments

Comments
 (0)