mirror of
https://github.com/kevin-DL/revel-cmd.git
synced 2026-01-11 18:54:31 +00:00
Overwrites generated app files instead of deleting directory
This commit is contained in:
@@ -162,14 +162,44 @@ func getAppVersion() string {
|
||||
|
||||
func cleanSource(dirs ...string) {
|
||||
for _, dir := range dirs {
|
||||
tmpPath := path.Join(revel.AppPath, dir)
|
||||
err := os.RemoveAll(tmpPath)
|
||||
cleanDir(dir)
|
||||
if err != nil {
|
||||
revel.ERROR.Println("Failed to remove dir:", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func cleanDir(dir string) {
|
||||
revel.INFO.Println("Cleaning dir " + dir)
|
||||
tmpPath := path.Join(revel.AppPath, dir)
|
||||
f, err := os.Open(tmpPath)
|
||||
if err != nil {
|
||||
revel.ERROR.Println("Failed to clean dir:", err)
|
||||
} else {
|
||||
defer f.Close()
|
||||
infos, err := f.Readdir(0)
|
||||
if err != nil {
|
||||
revel.ERROR.Println("Failed to clean dir:", err)
|
||||
} else {
|
||||
for _, info := range infos {
|
||||
path := path.Join(tmpPath, info.Name())
|
||||
if info.IsDir() {
|
||||
err := os.RemoveAll(path)
|
||||
if err != nil {
|
||||
revel.ERROR.Println("Failed to remove dir:", err)
|
||||
}
|
||||
} else {
|
||||
err := os.Remove(path)
|
||||
if err != nil {
|
||||
revel.ERROR.Println("Failed to remove file:", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// genSource renders the given template to produce source code, which it writes
|
||||
// to the given directory and file.
|
||||
func genSource(dir, filename, templateSource string, args map[string]interface{}) {
|
||||
@@ -178,14 +208,11 @@ func genSource(dir, filename, templateSource string, args map[string]interface{}
|
||||
args)
|
||||
|
||||
// Create a fresh dir.
|
||||
cleanSource(dir)
|
||||
tmpPath := path.Join(revel.AppPath, dir)
|
||||
err := os.RemoveAll(tmpPath)
|
||||
if err != nil {
|
||||
revel.ERROR.Println("Failed to remove dir:", err)
|
||||
}
|
||||
err = os.Mkdir(tmpPath, 0777)
|
||||
if err != nil {
|
||||
revel.ERROR.Fatalf("Failed to make tmp directory: %v", err)
|
||||
err := os.Mkdir(tmpPath, 0777)
|
||||
if err != nil && !os.IsExist(err) {
|
||||
revel.ERROR.Fatalf("Failed to make '%v' directory: %v", dir, err)
|
||||
}
|
||||
|
||||
// Create the file
|
||||
|
||||
Reference in New Issue
Block a user