From 97ea34cc80b44cf0a0a4fce88d6b6bb9171427d0 Mon Sep 17 00:00:00 2001 From: ZhengYang Date: Thu, 28 Aug 2014 17:31:37 +0800 Subject: [PATCH] truncate before overwritten --- g_appcode.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/g_appcode.go b/g_appcode.go index bb26b45..72322b5 100644 --- a/g_appcode.go +++ b/g_appcode.go @@ -731,7 +731,7 @@ func writeModelFiles(tables []*Table, mPath string, selectedTables map[string]bo if isExist(fpath) { ColorLog("[WARN] %v is exist, do you want to overwrite it? Yes or No?\n", fpath) if askForConfirmation() { - f, err = os.OpenFile(fpath, os.O_RDWR, 0666) + f, err = os.OpenFile(fpath, os.O_RDWR|os.O_TRUNC, 0666) if err != nil { ColorLog("[WARN] %v\n", err) continue @@ -793,7 +793,7 @@ func writeControllerFiles(tables []*Table, cPath string, selectedTables map[stri if isExist(fpath) { ColorLog("[WARN] %v is exist, do you want to overwrite it? Yes or No?\n", fpath) if askForConfirmation() { - f, err = os.OpenFile(fpath, os.O_RDWR, 0666) + f, err = os.OpenFile(fpath, os.O_RDWR|os.O_TRUNC, 0666) if err != nil { ColorLog("[WARN] %v\n", err) continue @@ -848,7 +848,7 @@ func writeRouterFile(tables []*Table, rPath string, selectedTables map[string]bo if isExist(fpath) { ColorLog("[WARN] %v is exist, do you want to overwrite it? Yes or No?\n", fpath) if askForConfirmation() { - f, err = os.OpenFile(fpath, os.O_RDWR, 0666) + f, err = os.OpenFile(fpath, os.O_RDWR|os.O_TRUNC, 0666) if err != nil { ColorLog("[WARN] %v\n", err) return