13 func (g *FileGetter) Get(dst string, u *url.URL) error {
19 // The source path must exist and be a directory to be usable.
20 if fi, err := os.Stat(path); err != nil {
21 return fmt.Errorf("source path error: %s", err)
22 } else if !fi.IsDir() {
23 return fmt.Errorf("source path must be a directory")
26 fi, err := os.Lstat(dst)
27 if err != nil && !os.IsNotExist(err) {
31 // If the destination already exists, it must be a symlink
34 if mode&os.ModeSymlink == 0 {
35 return fmt.Errorf("destination exists and is not a symlink")
38 // Remove the destination
39 if err := os.Remove(dst); err != nil {
44 // Create all the parent directories
45 if err := os.MkdirAll(filepath.Dir(dst), 0755); err != nil {
49 return os.Symlink(path, dst)
52 func (g *FileGetter) GetFile(dst string, u *url.URL) error {
58 // The source path must exist and be a file to be usable.
59 if fi, err := os.Stat(path); err != nil {
60 return fmt.Errorf("source path error: %s", err)
61 } else if fi.IsDir() {
62 return fmt.Errorf("source path must be a file")
65 _, err := os.Lstat(dst)
66 if err != nil && !os.IsNotExist(err) {
70 // If the destination already exists, it must be a symlink
72 // Remove the destination
73 if err := os.Remove(dst); err != nil {
78 // Create all the parent directories
79 if err := os.MkdirAll(filepath.Dir(dst), 0755); err != nil {
83 // If we're not copying, just symlink and we're done
85 return os.Symlink(path, dst)
89 srcF, err := os.Open(path)
95 dstF, err := os.Create(dst)
101 _, err = io.Copy(dstF, srcF)