v15.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Copyright 2017 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package migrations
  5. import (
  6. "fmt"
  7. "io/ioutil"
  8. "os"
  9. "path/filepath"
  10. "strings"
  11. "github.com/Unknwon/com"
  12. "github.com/go-xorm/xorm"
  13. log "gopkg.in/clog.v1"
  14. "github.com/gogits/gogs/modules/setting"
  15. )
  16. func generateAndMigrateGitHooks(x *xorm.Engine) (err error) {
  17. type Repository struct {
  18. ID int64
  19. OwnerID int64
  20. Name string
  21. }
  22. type User struct {
  23. ID int64
  24. Name string
  25. }
  26. var (
  27. hookNames = []string{"pre-receive", "update", "post-receive"}
  28. hookTpls = []string{
  29. fmt.Sprintf("#!/usr/bin/env %s\n\"%s\" hook --config='%s' pre-receive\n", setting.ScriptType, setting.AppPath, setting.CustomConf),
  30. fmt.Sprintf("#!/usr/bin/env %s\n\"%s\" hook --config='%s' update $1 $2 $3\n", setting.ScriptType, setting.AppPath, setting.CustomConf),
  31. fmt.Sprintf("#!/usr/bin/env %s\n\"%s\" hook --config='%s' post-receive\n", setting.ScriptType, setting.AppPath, setting.CustomConf),
  32. }
  33. )
  34. // Cleanup old update.log and http.log files.
  35. filepath.Walk(setting.LogRootPath, func(path string, info os.FileInfo, err error) error {
  36. if !info.IsDir() &&
  37. (strings.HasPrefix(filepath.Base(path), "update.log") ||
  38. strings.HasPrefix(filepath.Base(path), "http.log")) {
  39. os.Remove(path)
  40. }
  41. return nil
  42. })
  43. return x.Where("id > 0").Iterate(new(Repository),
  44. func(idx int, bean interface{}) error {
  45. repo := bean.(*Repository)
  46. if repo.Name == "." || repo.Name == ".." {
  47. return nil
  48. }
  49. user := new(User)
  50. has, err := x.Where("id = ?", repo.OwnerID).Get(user)
  51. if err != nil {
  52. return fmt.Errorf("query owner of repository [repo_id: %d, owner_id: %d]: %v", repo.ID, repo.OwnerID, err)
  53. } else if !has {
  54. return nil
  55. }
  56. repoBase := filepath.Join(setting.RepoRootPath, strings.ToLower(user.Name), strings.ToLower(repo.Name))
  57. repoPath := repoBase + ".git"
  58. wikiPath := repoBase + ".wiki.git"
  59. log.Trace("[%04d]: %s", idx, repoPath)
  60. hookDir := filepath.Join(repoPath, "hooks")
  61. customHookDir := filepath.Join(repoPath, "custom_hooks")
  62. wikiHookDir := filepath.Join(wikiPath, "hooks")
  63. for i, hookName := range hookNames {
  64. oldHookPath := filepath.Join(hookDir, hookName)
  65. newHookPath := filepath.Join(customHookDir, hookName)
  66. // Gogs didn't allow user to set custom update hook thus no migration for it.
  67. // In case user runs this migration multiple times, and custom hook exists,
  68. // we assume it's been migrated already.
  69. if hookName != "update" && com.IsFile(oldHookPath) && !com.IsExist(customHookDir) {
  70. os.MkdirAll(customHookDir, os.ModePerm)
  71. if err = os.Rename(oldHookPath, newHookPath); err != nil {
  72. return fmt.Errorf("move hook file to custom directory '%s' -> '%s': %v", oldHookPath, newHookPath, err)
  73. }
  74. }
  75. if err = ioutil.WriteFile(oldHookPath, []byte(hookTpls[i]), os.ModePerm); err != nil {
  76. return fmt.Errorf("write hook file '%s': %v", oldHookPath, err)
  77. }
  78. if com.IsDir(wikiPath) {
  79. os.MkdirAll(wikiHookDir, os.ModePerm)
  80. wikiHookPath := filepath.Join(wikiHookDir, hookName)
  81. if err = ioutil.WriteFile(wikiHookPath, []byte(hookTpls[i]), os.ModePerm); err != nil {
  82. return fmt.Errorf("write wiki hook file '%s': %v", wikiHookPath, err)
  83. }
  84. }
  85. }
  86. return nil
  87. })
  88. }
PANIC: session(release): write data/sessions/6/c/6c43a96bd66499c3: no space left on device

PANIC

session(release): write data/sessions/6/c/6c43a96bd66499c3: no space left on device
github.com/go-macaron/session@v0.0.0-20190805070824-1a3cdc6f5659/session.go:199 (0x8b2934)
gopkg.in/macaron.v1@v1.3.9/context.go:79 (0x83d0a0)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:157 (0x80ab07)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:135 (0x80a8a8)
gopkg.in/macaron.v1@v1.3.9/context.go:121 (0x83d1f8)
gopkg.in/macaron.v1@v1.3.9/context.go:112 (0x84fdb5)
gopkg.in/macaron.v1@v1.3.9/recovery.go:161 (0x84fda8)
gopkg.in/macaron.v1@v1.3.9/logger.go:40 (0x840c73)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:157 (0x80ab07)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:135 (0x80a8a8)
gopkg.in/macaron.v1@v1.3.9/context.go:121 (0x83d1f8)
gopkg.in/macaron.v1@v1.3.9/router.go:187 (0x850fc6)
gopkg.in/macaron.v1@v1.3.9/router.go:303 (0x8493e5)
gopkg.in/macaron.v1@v1.3.9/macaron.go:220 (0x841fca)
net/http/server.go:2836 (0x7a79b2)
net/http/server.go:1924 (0x7a341b)
runtime/asm_amd64.s:1373 (0x46f9f0)