MCPcopy Create free account
hub / github.com/OpenAtomFoundation/SmartIDE / copyFile

Function copyFile

cli/cmd/new/newLocal.go:181–212  ·  view source on GitHub ↗

生成目录并拷贝文件

(src, dest string)

Source from the content-addressed store, hash-verified

179
180// 生成目录并拷贝文件
181func copyFile(src, dest string) (w int64, err error) {
182 srcFile, err := os.Open(src)
183 if err != nil {
184 fmt.Println(err.Error())
185 return
186 }
187 defer srcFile.Close()
188 //分割path目录
189 destSplitPathDirs := strings.Split(dest, "/")
190 //检测时候存在目录
191 destSplitPath := ""
192 for index, dir := range destSplitPathDirs {
193 if index < len(destSplitPathDirs)-1 {
194 destSplitPath = destSplitPath + dir + "/"
195 b := common.IsExist(destSplitPath)
196 if !b {
197 //创建目录
198 err := os.Mkdir(destSplitPath, os.ModePerm)
199 if err != nil {
200 fmt.Println(err)
201 }
202 }
203 }
204 }
205 dstFile, err := os.Create(dest)
206 if err != nil {
207 fmt.Println(err.Error())
208 return
209 }
210 defer dstFile.Close()
211 return io.Copy(dstFile, srcFile)
212}

Callers 1

copyDirFunction · 0.70

Calls 3

IsExistMethod · 0.80
CopyMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected