You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2018/04/21 07:29:37 UTC

[incubator-servicecomb-service-center] branch master updated: SCB-510 Expire backup log files are not removed (#330)

This is an automated email from the ASF dual-hosted git repository.

littlecui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-service-center.git


The following commit(s) were added to refs/heads/master by this push:
     new 0d3e067  SCB-510 Expire backup log files are not removed (#330)
0d3e067 is described below

commit 0d3e06758857c8b4ef2c37e1be9f6b7fa19a9c81
Author: little-cui <su...@qq.com>
AuthorDate: Sat Apr 21 15:29:34 2018 +0800

    SCB-510 Expire backup log files are not removed (#330)
    
    * SCB-510 Expire backup log files are not removed
    
    * SCB-510 add some comments
---
 pkg/util/logrotate.go | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/pkg/util/logrotate.go b/pkg/util/logrotate.go
index e7dbcef..fe820af 100644
--- a/pkg/util/logrotate.go
+++ b/pkg/util/logrotate.go
@@ -66,7 +66,7 @@ func removeExceededFiles(path string, baseFileName string,
 	} else {
 		return
 	}
-	fileList, err := FilterFileList(path, pat)
+	fileList, err := FilterFileList(path, pat, 0777)
 	if err != nil {
 		Logger().Error("filepath.Walk() "+EscapPath(path)+" failed", err)
 		return
@@ -176,7 +176,7 @@ func doBackup(fPath string, MaxBackupCount int) {
 		return
 	}
 	pat := fmt.Sprintf(`%s\.[0-9]{1,17}$`, filepath.Base(fPath))
-	rotateFileList, err := FilterFileList(filepath.Dir(fPath), pat)
+	rotateFileList, err := FilterFileList(filepath.Dir(fPath), pat, 0777)
 	if err != nil {
 		Logger().Error("walk"+EscapPath(fPath)+" failed", err)
 		return
@@ -229,7 +229,7 @@ func LogRotate(path string, MaxFileSize int, MaxBackupCount int) {
 	}()
 
 	pat := `.(\.log|\.trace|\.out)$`
-	fileList, err := FilterFileList(path, pat)
+	fileList, err := FilterFileList(path, pat, 0200)
 	if err != nil {
 		Logger().Error("filepath.Walk() "+EscapPath(path)+" failed", err)
 		return
@@ -240,14 +240,15 @@ func LogRotate(path string, MaxFileSize int, MaxBackupCount int) {
 	}
 }
 
-func isSkip(f os.FileInfo) bool {
-	//dir or non write permission,skip
-	return f.IsDir() || (f.Mode()&0200 == 0000)
+func isSkip(f os.FileInfo, permits os.FileMode) bool {
+	//dir or permission deny
+	return f.IsDir() || (f.Mode()&permits == 0000)
 }
 
-//path : where the file will be filtered
-//pat  : regexp pattern to filter the matched file
-func FilterFileList(path, pat string) ([]string, error) {
+//path    : where the file will be filtered
+//pat     : regexp pattern to filter the matched file
+//permit  : check the file whether match any of the permits or not
+func FilterFileList(path, pat string, permits os.FileMode) ([]string, error) {
 	capacity := 10
 	//initialize a fileName slice, len=0, cap=10
 	fileList := make([]string, 0, capacity)
@@ -257,7 +258,7 @@ func FilterFileList(path, pat string) ([]string, error) {
 			if f == nil {
 				return e
 			}
-			if isSkip(f) {
+			if isSkip(f, permits) {
 				return nil
 			}
 			if pat != "" {

-- 
To stop receiving notification emails like this one, please contact
littlecui@apache.org.