-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d7839e9
commit 1a7b9dd
Showing
12 changed files
with
130 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package utils | ||
|
||
import ( | ||
"io" | ||
"io/ioutil" | ||
"os" | ||
"path" | ||
) | ||
|
||
func Copy(src, dst string) error { | ||
var err error | ||
var srcinfo os.FileInfo | ||
|
||
if srcinfo, err = os.Stat(src); err != nil { | ||
return err | ||
} | ||
|
||
if !srcinfo.IsDir() { | ||
return copyFile(src, dst) | ||
} | ||
return copyDir(src, dst) | ||
} | ||
|
||
func copyFile(src, dst string) error { | ||
var err error | ||
var srcfd *os.File | ||
var dstfd *os.File | ||
var srcinfo os.FileInfo | ||
|
||
if srcfd, err = os.Open(src); err != nil { | ||
return err | ||
} | ||
defer srcfd.Close() | ||
|
||
if dstfd, err = os.Create(dst); err != nil { | ||
return err | ||
} | ||
defer dstfd.Close() | ||
|
||
if _, err = io.Copy(dstfd, srcfd); err != nil { | ||
return err | ||
} | ||
if srcinfo, err = os.Stat(src); err != nil { | ||
return err | ||
} | ||
return os.Chmod(dst, srcinfo.Mode()) | ||
} | ||
|
||
func copyDir(src string, dst string) error { | ||
var err error | ||
var fds []os.FileInfo | ||
var srcinfo os.FileInfo | ||
|
||
if srcinfo, err = os.Stat(src); err != nil { | ||
return err | ||
} | ||
|
||
if err = os.MkdirAll(dst, srcinfo.Mode()); err != nil { | ||
return err | ||
} | ||
|
||
if fds, err = ioutil.ReadDir(src); err != nil { | ||
return err | ||
} | ||
for _, fd := range fds { | ||
srcfp := path.Join(src, fd.Name()) | ||
dstfp := path.Join(dst, fd.Name()) | ||
|
||
if fd.IsDir() { | ||
if err = copyDir(srcfp, dstfp); err != nil { | ||
return err | ||
} | ||
} else { | ||
if err = copyFile(srcfp, dstfp); err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters