mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 06:19:45 +00:00 
			
		
		
		
	Fix bug related to log
This commit is contained in:
		
							
								
								
									
										2
									
								
								gogs.go
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								gogs.go
									
									
									
									
									
								
							| @@ -19,7 +19,7 @@ import ( | |||||||
| // Test that go1.2 tag above is included in builds. main.go refers to this definition. | // Test that go1.2 tag above is included in builds. main.go refers to this definition. | ||||||
| const go12tag = true | const go12tag = true | ||||||
|  |  | ||||||
| const APP_VER = "0.2.1.0405 Alpha" | const APP_VER = "0.2.1.0406 Alpha" | ||||||
|  |  | ||||||
| func init() { | func init() { | ||||||
| 	base.AppVer = APP_VER | 	base.AppVer = APP_VER | ||||||
|   | |||||||
							
								
								
									
										53
									
								
								serve.go
									
									
									
									
									
								
							
							
						
						
									
										53
									
								
								serve.go
									
									
									
									
									
								
							| @@ -14,7 +14,7 @@ import ( | |||||||
| 	"strings" | 	"strings" | ||||||
|  |  | ||||||
| 	"github.com/codegangsta/cli" | 	"github.com/codegangsta/cli" | ||||||
| 	"github.com/gogits/gogs/modules/log" | 	qlog "github.com/qiniu/log" | ||||||
|  |  | ||||||
| 	//"github.com/gogits/git" | 	//"github.com/gogits/git" | ||||||
| 	"github.com/gogits/gogs/models" | 	"github.com/gogits/gogs/models" | ||||||
| @@ -44,11 +44,15 @@ gogs serv provide access auth for repositories`, | |||||||
| } | } | ||||||
|  |  | ||||||
| func newLogger(execDir string) { | func newLogger(execDir string) { | ||||||
| 	level := "0" |  | ||||||
| 	logPath := execDir + "/log/serv.log" | 	logPath := execDir + "/log/serv.log" | ||||||
| 	os.MkdirAll(path.Dir(logPath), os.ModePerm) | 	os.MkdirAll(path.Dir(logPath), os.ModePerm) | ||||||
| 	log.NewLogger(0, "file", fmt.Sprintf(`{"level":%s,"filename":"%s"}`, level, logPath)) | 	f, err := os.Open(logPath) | ||||||
| 	log.Trace("start logging...") | 	if err != nil { | ||||||
|  | 		qlog.Fatal(err) | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	qlog.SetOutput(f) | ||||||
|  | 	qlog.Info("Start logging serv...") | ||||||
| } | } | ||||||
|  |  | ||||||
| func parseCmd(cmd string) (string, string) { | func parseCmd(cmd string) (string, string) { | ||||||
| @@ -87,21 +91,18 @@ func runServ(k *cli.Context) { | |||||||
| 	keys := strings.Split(os.Args[2], "-") | 	keys := strings.Split(os.Args[2], "-") | ||||||
| 	if len(keys) != 2 { | 	if len(keys) != 2 { | ||||||
| 		println("auth file format error") | 		println("auth file format error") | ||||||
| 		log.Error("auth file format error") | 		qlog.Fatal("auth file format error") | ||||||
| 		return |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	keyId, err := strconv.ParseInt(keys[1], 10, 64) | 	keyId, err := strconv.ParseInt(keys[1], 10, 64) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		println("auth file format error") | 		println("auth file format error") | ||||||
| 		log.Error("auth file format error", err) | 		qlog.Fatal("auth file format error", err) | ||||||
| 		return |  | ||||||
| 	} | 	} | ||||||
| 	user, err := models.GetUserByKeyId(keyId) | 	user, err := models.GetUserByKeyId(keyId) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		println("You have no right to access") | 		println("You have no right to access") | ||||||
| 		log.Error("SSH visit error: %v", err) | 		qlog.Fatalf("SSH visit error: %v", err) | ||||||
| 		return |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	cmd := os.Getenv("SSH_ORIGINAL_COMMAND") | 	cmd := os.Getenv("SSH_ORIGINAL_COMMAND") | ||||||
| @@ -115,8 +116,7 @@ func runServ(k *cli.Context) { | |||||||
| 	rr := strings.SplitN(repoPath, "/", 2) | 	rr := strings.SplitN(repoPath, "/", 2) | ||||||
| 	if len(rr) != 2 { | 	if len(rr) != 2 { | ||||||
| 		println("Unavilable repository", args) | 		println("Unavilable repository", args) | ||||||
| 		log.Error("Unavilable repository %v", args) | 		qlog.Fatalf("Unavilable repository %v", args) | ||||||
| 		return |  | ||||||
| 	} | 	} | ||||||
| 	repoUserName := rr[0] | 	repoUserName := rr[0] | ||||||
| 	repoName := rr[1] | 	repoName := rr[1] | ||||||
| @@ -129,9 +129,8 @@ func runServ(k *cli.Context) { | |||||||
|  |  | ||||||
| 	repoUser, err := models.GetUserByName(repoUserName) | 	repoUser, err := models.GetUserByName(repoUserName) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		fmt.Println("You have no right to access") | 		println("You have no right to access") | ||||||
| 		log.Error("Get user failed", err) | 		qlog.Fatal("Get user failed", err) | ||||||
| 		return |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// access check | 	// access check | ||||||
| @@ -140,19 +139,16 @@ func runServ(k *cli.Context) { | |||||||
| 		has, err := models.HasAccess(user.LowerName, path.Join(repoUserName, repoName), models.AU_WRITABLE) | 		has, err := models.HasAccess(user.LowerName, path.Join(repoUserName, repoName), models.AU_WRITABLE) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			println("Inernel error:", err) | 			println("Inernel error:", err) | ||||||
| 			log.Error(err.Error()) | 			qlog.Fatal(err) | ||||||
| 			return |  | ||||||
| 		} else if !has { | 		} else if !has { | ||||||
| 			println("You have no right to write this repository") | 			println("You have no right to write this repository") | ||||||
| 			log.Error("User %s has no right to write repository %s", user.Name, repoPath) | 			qlog.Fatalf("User %s has no right to write repository %s", user.Name, repoPath) | ||||||
| 			return |  | ||||||
| 		} | 		} | ||||||
| 	case isRead: | 	case isRead: | ||||||
| 		repo, err := models.GetRepositoryByName(repoUser.Id, repoName) | 		repo, err := models.GetRepositoryByName(repoUser.Id, repoName) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			println("Get repository error:", err) | 			println("Get repository error:", err) | ||||||
| 			log.Error("Get repository error: " + err.Error()) | 			qlog.Fatal("Get repository error: " + err.Error()) | ||||||
| 			return |  | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		if !repo.IsPrivate { | 		if !repo.IsPrivate { | ||||||
| @@ -162,26 +158,22 @@ func runServ(k *cli.Context) { | |||||||
| 		has, err := models.HasAccess(user.Name, repoPath, models.AU_READABLE) | 		has, err := models.HasAccess(user.Name, repoPath, models.AU_READABLE) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			println("Inernel error") | 			println("Inernel error") | ||||||
| 			log.Error(err.Error()) | 			qlog.Fatal(err) | ||||||
| 			return |  | ||||||
| 		} | 		} | ||||||
| 		if !has { | 		if !has { | ||||||
| 			has, err = models.HasAccess(user.Name, repoPath, models.AU_WRITABLE) | 			has, err = models.HasAccess(user.Name, repoPath, models.AU_WRITABLE) | ||||||
| 			if err != nil { | 			if err != nil { | ||||||
| 				println("Inernel error") | 				println("Inernel error") | ||||||
| 				log.Error(err.Error()) | 				qlog.Fatal(err) | ||||||
| 				return |  | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		if !has { | 		if !has { | ||||||
| 			println("You have no right to access this repository") | 			println("You have no right to access this repository") | ||||||
| 			log.Error("You have no right to access this repository") | 			qlog.Fatal("You have no right to access this repository") | ||||||
| 			return |  | ||||||
| 		} | 		} | ||||||
| 	default: | 	default: | ||||||
| 		println("Unknown command") | 		println("Unknown command") | ||||||
| 		log.Error("Unknown command") | 		qlog.Fatal("Unknown command") | ||||||
| 		return |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// for update use | 	// for update use | ||||||
| @@ -197,7 +189,6 @@ func runServ(k *cli.Context) { | |||||||
|  |  | ||||||
| 	if err = gitcmd.Run(); err != nil { | 	if err = gitcmd.Run(); err != nil { | ||||||
| 		println("execute command error:", err.Error()) | 		println("execute command error:", err.Error()) | ||||||
| 		log.Error("execute command error: " + err.Error()) | 		qlog.Fatal("execute command error: " + err.Error()) | ||||||
| 		return |  | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
| @@ -92,13 +92,11 @@ func runUpdate(c *cli.Context) { | |||||||
| 	newOid, err := git.NewOidFromString(newCommitId) | 	newOid, err := git.NewOidFromString(newCommitId) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		qlog.Fatalf("runUpdate.Ref repoId: %v", err) | 		qlog.Fatalf("runUpdate.Ref repoId: %v", err) | ||||||
| 		return |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	newCommit, err := repo.LookupCommit(newOid) | 	newCommit, err := repo.LookupCommit(newOid) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		qlog.Fatalf("runUpdate.Ref repoId: %v", err) | 		qlog.Fatalf("runUpdate.Ref repoId: %v", err) | ||||||
| 		return |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	var l *list.List | 	var l *list.List | ||||||
| @@ -107,38 +105,32 @@ func runUpdate(c *cli.Context) { | |||||||
| 		l, err = repo.CommitsBefore(newCommit.Id()) | 		l, err = repo.CommitsBefore(newCommit.Id()) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			qlog.Fatalf("Find CommitsBefore erro:", err) | 			qlog.Fatalf("Find CommitsBefore erro:", err) | ||||||
| 			return |  | ||||||
| 		} | 		} | ||||||
| 	} else { | 	} else { | ||||||
| 		oldOid, err := git.NewOidFromString(oldCommitId) | 		oldOid, err := git.NewOidFromString(oldCommitId) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			qlog.Fatalf("runUpdate.Ref repoId: %v", err) | 			qlog.Fatalf("runUpdate.Ref repoId: %v", err) | ||||||
| 			return |  | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		oldCommit, err := repo.LookupCommit(oldOid) | 		oldCommit, err := repo.LookupCommit(oldOid) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			qlog.Fatalf("runUpdate.Ref repoId: %v", err) | 			qlog.Fatalf("runUpdate.Ref repoId: %v", err) | ||||||
| 			return |  | ||||||
| 		} | 		} | ||||||
| 		l = repo.CommitsBetween(newCommit, oldCommit) | 		l = repo.CommitsBetween(newCommit, oldCommit) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		qlog.Fatalf("runUpdate.Commit repoId: %v", err) | 		qlog.Fatalf("runUpdate.Commit repoId: %v", err) | ||||||
| 		return |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	sUserId, err := strconv.Atoi(userId) | 	sUserId, err := strconv.Atoi(userId) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		qlog.Fatalf("runUpdate.Parse userId: %v", err) | 		qlog.Fatalf("runUpdate.Parse userId: %v", err) | ||||||
| 		return |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	repos, err := models.GetRepositoryByName(int64(sUserId), repoName) | 	repos, err := models.GetRepositoryByName(int64(sUserId), repoName) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		qlog.Fatalf("runUpdate.GetRepositoryByName userId: %v", err) | 		qlog.Fatalf("runUpdate.GetRepositoryByName userId: %v", err) | ||||||
| 		return |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	commits := make([]*base.PushCommit, 0) | 	commits := make([]*base.PushCommit, 0) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user