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

Function copyFile

cli/cmd/init/local.go:117–148  ·  view source on GitHub ↗

生成目录并拷贝文件

(src, dest string)

Source from the content-addressed store, hash-verified

115
116// 生成目录并拷贝文件
117func copyFile(src, dest string) (w int64, err error) {
118 srcFile, err := os.Open(src)
119 if err != nil {
120 fmt.Println(err.Error())
121 return
122 }
123 defer srcFile.Close()
124 //分割path目录
125 destSplitPathDirs := strings.Split(dest, "/")
126 //检测时候存在目录
127 destSplitPath := ""
128 for index, dir := range destSplitPathDirs {
129 if index < len(destSplitPathDirs)-1 {
130 destSplitPath = destSplitPath + dir + "/"
131 b := common.IsExist(destSplitPath)
132 if !b {
133 //创建目录
134 err := os.Mkdir(destSplitPath, os.ModePerm)
135 if err != nil {
136 fmt.Println(err)
137 }
138 }
139 }
140 }
141 dstFile, err := os.Create(dest)
142 if err != nil {
143 fmt.Println(err.Error())
144 return
145 }
146 defer dstFile.Close()
147 return io.Copy(dstFile, srcFile)
148}
149
150// 从command的参数中获取模板设置信息
151func getTemplateSetting(cmd *cobra.Command, args []string) (*TemplateTypeBo, error) {

Callers 1

copyDirFunction · 0.70

Calls 3

IsExistMethod · 0.80
CopyMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected