fix: account balance failed when file is not exist.
This commit is contained in:
parent
09f58fef64
commit
f2d1e7329b
|
|
@ -38,6 +38,10 @@ func WriteFile(filePath string, content string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func AppendFileInNewLine(filePath string, content string) error {
|
func AppendFileInNewLine(filePath string, content string) error {
|
||||||
|
err := CreateFileIfNotExist(filePath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
content = "\r\n" + content
|
content = "\r\n" + content
|
||||||
file, err := os.OpenFile(filePath, os.O_APPEND|os.O_WRONLY, os.ModeAppend)
|
file, err := os.OpenFile(filePath, os.O_APPEND|os.O_WRONLY, os.ModeAppend)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -71,6 +75,20 @@ func CreateFile(filePath string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CreateFileIfNotExist(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")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
LogSystemInfo("Success create file " + filePath)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func CopyFile(sourceFilePath string, targetFilePath string) error {
|
func CopyFile(sourceFilePath string, targetFilePath string) error {
|
||||||
if !FileIfExist(sourceFilePath) {
|
if !FileIfExist(sourceFilePath) {
|
||||||
panic("File is not found, " + sourceFilePath)
|
panic("File is not found, " + sourceFilePath)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue