Skip to content

Commit

Permalink
Merge pull request #172 from Bitspark/copy-insteadof-rename
Browse files Browse the repository at this point in the history
Copy instead of renaming downloaded files
  • Loading branch information
jm9e authored Aug 26, 2018
2 parents 44feb00 + f378cb3 commit dcc9e12
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
8 changes: 2 additions & 6 deletions pkg/daemon/component_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,7 @@ func (dl *SlangComponentLoader) replaceDirContentBy(newDirPath string) error {
os.RemoveAll(dl.path)
}

if err = os.MkdirAll(dl.path, os.ModePerm); err != nil {
return err
}

if err = moveAll(newDirPath, dl.path, true); err != nil {
if err = copyAll(newDirPath, dl.path, true); err != nil {
return err
}

Expand Down Expand Up @@ -205,4 +201,4 @@ func IsNewestSlangVersion(myVerStr string) (bool, string, error) {
return false, *release.TagName, nil
}
return true, *release.TagName, nil
}
}
21 changes: 19 additions & 2 deletions pkg/daemon/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,24 @@ func toVersion(verstr string) *version.Version {
return v
}

func moveAll(srcDir string, dstDir string, skipFirstLevel bool) error {
func copy(srcPath string, dstPath string) (error) {
srcFile, err := os.OpenFile(srcPath, os.O_RDONLY, os.ModePerm)
if err != nil {
return err
}
defer srcFile.Close()

dstFile, err := os.OpenFile(dstPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.ModePerm)
if err != nil {
return err
}

_, err = io.Copy(dstFile, srcFile)

return err
}

func copyAll(srcDir string, dstDir string, skipFirstLevel bool) error {
var outerErr error
filepath.Walk(srcDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
Expand Down Expand Up @@ -148,7 +165,7 @@ func moveAll(srcDir string, dstDir string, skipFirstLevel bool) error {
return err
}

if err = os.Rename(path, dstFilePath); err != nil {
if err = copy(path, dstFilePath); err != nil {
outerErr = err
return err
}
Expand Down

0 comments on commit dcc9e12

Please sign in to comment.