diff options
author | Unknown <joe2010xtmf@163.com> | 2014-04-12 21:30:09 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-04-12 21:30:09 -0400 |
commit | 9ffa8a40836a5e3341267affbaef08acf4765a74 (patch) | |
tree | afc0c9b13c02c22b577bcfc498b0ced973aa1495 /models | |
parent | 90f6aa8cd19e489723ddffc40d6507782c29756c (diff) | |
download | gitea-9ffa8a40836a5e3341267affbaef08acf4765a74.tar.gz gitea-9ffa8a40836a5e3341267affbaef08acf4765a74.zip |
finish mirror fix #63
Diffstat (limited to 'models')
-rw-r--r-- | models/repo.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/models/repo.go b/models/repo.go index a2c63a50c9..ae8fe5efd1 100644 --- a/models/repo.go +++ b/models/repo.go @@ -130,6 +130,32 @@ type Mirror struct { NextUpdate time.Time } +// MirrorUpdate checks and updates mirror repositories. +func MirrorUpdate() { + if err := orm.Iterate(new(Mirror), func(idx int, bean interface{}) error { + m := bean.(*Mirror) + if m.NextUpdate.After(time.Now()) { + return nil + } + + repoPath := filepath.Join(base.RepoRootPath, m.RepoName+".git") + _, stderr, err := com.ExecCmdDir(repoPath, "git", "remote", "update") + if err != nil { + return err + } else if strings.Contains(stderr, "fatal:") { + return errors.New(stderr) + } else if err = git.UnpackRefs(repoPath); err != nil { + return err + } + + m.NextUpdate = time.Now().Add(time.Duration(m.Interval) * time.Hour) + _, err = orm.Id(m.Id).Update(m) + return err + }); err != nil { + log.Error("repo.MirrorUpdate: %v", err) + } +} + // MirrorRepository creates a mirror repository from source. func MirrorRepository(repoId int64, userName, repoName, repoPath, url string) error { _, stderr, err := com.ExecCmd("git", "clone", "--mirror", url, repoPath) |