Skip to content

Commit 7408627

Browse files
authored
Merge pull request #76 from kcl-lang/feat-write-lib-windows
feat: write lib without temp renaming file on windows
2 parents 7b70a97 + 66ddb7d commit 7408627

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

util.go renamed to util_unix.go

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build linux || darwin
2+
// +build linux darwin
3+
14
package lib
25

36
import (

util_windows.go

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package lib
2+
3+
import (
4+
"os"
5+
"path/filepath"
6+
)
7+
8+
func writeLib(libDir, libFullName string, content []byte, versionMatched bool) error {
9+
libFullPath := filepath.Join(libDir, libFullName)
10+
_, err := os.Stat(libFullPath)
11+
if os.IsNotExist(err) || !versionMatched {
12+
err = os.MkdirAll(libDir, 0777)
13+
if err != nil {
14+
return err
15+
}
16+
libFile, err := os.Create(libFullPath)
17+
defer func() {
18+
libFile.Close()
19+
}()
20+
if err != nil {
21+
return err
22+
}
23+
_, err = libFile.Write(content)
24+
if err != nil {
25+
return err
26+
}
27+
}
28+
return err
29+
}

0 commit comments

Comments
 (0)