From f8182ac5216153f9ac6dbfe31437b03ddadbf286 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Fri, 5 Feb 2016 14:11:53 -0500 Subject: #2558 delete local wiki copy when rename repo and user --- models/admin.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'models/admin.go') diff --git a/models/admin.go b/models/admin.go index 1d6bf62961..811edde244 100644 --- a/models/admin.go +++ b/models/admin.go @@ -5,12 +5,15 @@ package models import ( + "fmt" + "os" "strings" "time" "github.com/Unknwon/com" "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/modules/log" ) type NoticeType int @@ -47,6 +50,18 @@ func CreateRepositoryNotice(desc string) error { return CreateNotice(NOTICE_REPOSITORY, desc) } +// RemoveAllWithNotice removes all directories in given path and +// creates a system notice when error occurs. +func RemoveAllWithNotice(title, path string) { + if err := os.RemoveAll(path); err != nil { + desc := fmt.Sprintf("%s [%s]: %v", title, path, err) + log.Warn(desc) + if err = CreateRepositoryNotice(desc); err != nil { + log.Error(4, "CreateRepositoryNotice: %v", err) + } + } +} + // CountNotices returns number of notices. func CountNotices() int64 { count, _ := x.Count(new(Notice)) -- cgit v1.2.3