Skip to content

Commit

Permalink
Use plain copy for folder sync
Browse files Browse the repository at this point in the history
  • Loading branch information
coufalja committed Feb 12, 2019
1 parent ed0f2f9 commit af035d0
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions pkg/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/imdario/mergo"
log "github.com/sirupsen/logrus"
"gopkg.in/src-d/go-git.v4/plumbing/object"
"io"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand All @@ -24,6 +25,7 @@ import (
)

const refAnnotation = "git2kube.github.com/ref"
const bufferSize = 1024

// LoadType upload type
type LoadType int
Expand Down Expand Up @@ -478,11 +480,40 @@ func (u *folderUploader) Upload(commitID string, iter FileIter) error {
if _, err := os.Lstat(src); err == nil {
src, _ = filepath.Abs(src)
}
dest := path.Join(u.name, file.Name)
if _, err := os.Lstat(dest); err == nil {
os.Remove(dest)
dst := path.Join(u.name, file.Name)

source, err := os.Open(src)
if err != nil {
return err
}
defer source.Close()

if dir, _ := filepath.Split(dst); dir != "" {
err = os.MkdirAll(dir, 0777)
if err != nil {
return err
}
}

destination, err := os.Create(dst)
if err != nil {
return err
}
defer destination.Close()

buf := make([]byte, bufferSize)
for {
n, err := source.Read(buf)
if err != nil && err != io.EOF {
return err
}
if n == 0 {
break
}
if _, err := destination.Write(buf[:n]); err != nil {
return err
}
}
return os.Symlink(src, dest)
}
return nil
})
Expand Down

0 comments on commit af035d0

Please sign in to comment.