This repository was archived by the owner on Oct 23, 2023. It is now read-only.
Commit 0323bcd 1 parent c90aef5 commit 0323bcd Copy full SHA for 0323bcd
File tree 1 file changed +38
-0
lines changed
1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ import (
27
27
"io/ioutil"
28
28
"os"
29
29
"os/exec"
30
+ "path"
30
31
"regexp"
31
32
"strconv"
32
33
"strings"
@@ -82,6 +83,43 @@ func CopyFile(srcPath, destPath string) error {
82
83
return nil
83
84
}
84
85
86
+ // CopyDir copies a whole directory recursively
87
+ // snippet from https://blog.depa.do/post/copy-files-and-directories-in-go
88
+ func CopyDir (srcPath string , dstPath string ) error {
89
+ var err error
90
+ var fds []os.FileInfo
91
+ var srcinfo os.FileInfo
92
+
93
+ srcinfo , err = os .Stat (srcPath )
94
+ if err != nil {
95
+ return err
96
+ }
97
+
98
+ err = os .MkdirAll (dstPath , srcinfo .Mode ())
99
+ if err != nil {
100
+ return err
101
+ }
102
+
103
+ if fds , err = ioutil .ReadDir (srcPath ); err != nil {
104
+ return err
105
+ }
106
+ for _ , fd := range fds {
107
+ srcfp := path .Join (srcPath , fd .Name ())
108
+ dstfp := path .Join (srcPath , fd .Name ())
109
+
110
+ if fd .IsDir () {
111
+ if err = CopyDir (srcfp , dstfp ); err != nil {
112
+ return err
113
+ }
114
+ } else {
115
+ if err = CopyFile (srcfp , dstfp ); err != nil {
116
+ return err
117
+ }
118
+ }
119
+ }
120
+ return nil
121
+ }
122
+
85
123
// CopyFileReplace copies a file within the snap and replaces strings using
86
124
// the string/replace values in the rStrings parameter.
87
125
func CopyFileReplace (srcPath , destPath string , rStrings map [string ]string ) error {
You can’t perform that action at this time.
0 commit comments