fix: failed to bak file cause by linux file system case sensitivity #20
This commit is contained in:
parent
81738c09d9
commit
517cb25e73
|
|
@ -3,6 +3,7 @@ package script
|
|||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func FileIfExist(filePath string) bool {
|
||||
|
|
@ -39,7 +40,10 @@ func WriteFile(filePath string, content string) error {
|
|||
func AppendFileInNewLine(filePath string, content string) error {
|
||||
content = "\r\n" + content
|
||||
file, err := os.OpenFile(filePath, os.O_APPEND|os.O_WRONLY, os.ModeAppend)
|
||||
if err == nil {
|
||||
if err != nil {
|
||||
LogSystemError("Failed to open file (" + filePath + ")")
|
||||
return err
|
||||
} else {
|
||||
_, err = file.WriteString(content)
|
||||
if err != nil {
|
||||
LogSystemError("Failed to append file (" + filePath + ")")
|
||||
|
|
@ -48,10 +52,12 @@ func AppendFileInNewLine(filePath string, content string) error {
|
|||
}
|
||||
defer file.Close()
|
||||
LogSystemInfo("Success append file (" + filePath + ")")
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
|
||||
func CreateFile(filePath string) error {
|
||||
if _, e := os.Stat(filePath); os.IsNotExist(e) {
|
||||
_ = os.MkdirAll(filepath.Dir(filePath), os.ModePerm)
|
||||
f, err := os.Create(filePath)
|
||||
if nil != err {
|
||||
LogSystemError(filePath + " create failed")
|
||||
|
|
@ -59,6 +65,9 @@ func CreateFile(filePath string) error {
|
|||
}
|
||||
defer f.Close()
|
||||
LogSystemInfo("Success create file " + filePath)
|
||||
} else {
|
||||
LogSystemInfo("File is exist " + filePath)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue