Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

preserve symlinks when copying #62

Merged
merged 1 commit into from

2 participants

@vito

Example repo with bogus symlinks as test fixtures:

https://github.com/dotcloud/docker/tree/master/utils/testdata/fs

Without this fix godep save chokes when copying the files, as their destination does not exist. It should be safe to preserve symlinks; anything checked in must be relative to the repository in the first place, so it should have the same behavior when vendored.

@kr kr merged commit de4fb95 into from
@kr
Owner
kr commented

Awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 9, 2014
  1. @vito

    preserve symlinks when copying

    vito authored
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 3 deletions.
  1. +12 −3 save.go
View
15 save.go
@@ -157,24 +157,33 @@ func copySrc(dir string, g *Godeps) error {
// copyFile copies a regular file from src to dst.
// dst is opened with os.Create.
func copyFile(dst, src string) error {
- r, err := os.Open(src)
+ err := os.MkdirAll(filepath.Dir(dst), 0777)
if err != nil {
return err
}
- defer r.Close()
- err = os.MkdirAll(filepath.Dir(dst), 0777)
+
+ linkDst, err := os.Readlink(src)
+ if err == nil {
+ return os.Symlink(linkDst, dst)
+ }
+
+ r, err := os.Open(src)
if err != nil {
return err
}
+ defer r.Close()
+
w, err := os.Create(dst)
if err != nil {
return err
}
+
_, err = io.Copy(w, r)
err1 := w.Close()
if err == nil {
err = err1
}
+
return err
}
Something went wrong with that request. Please try again.