Skip to content

Commit

Permalink
fix: if Mirrors repo no content is fetched, updated time should not b… (
Browse files Browse the repository at this point in the history
go-gitea#3551)

* fix: if Mirrors repo no content is fetched, updated time should not be changed

* fix: sync update time from mirror repo.

* fix: one single session.

* update comment.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
  • Loading branch information
appleboy authored and lunny committed Feb 23, 2018
1 parent e7cea92 commit 845ba9d
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion models/repo_mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ func MirrorUpdate() {
// SyncMirrors checks and syncs mirrors.
// TODO: sync more mirrors at same time.
func SyncMirrors() {
sess := x.NewSession()
defer sess.Close()
// Start listening on new sync requests.
for repoID := range MirrorQueue.Queue() {
log.Trace("SyncMirrors [repo_id: %v]", repoID)
Expand All @@ -260,10 +262,22 @@ func SyncMirrors() {
}

m.ScheduleNextUpdate()
if err = UpdateMirror(m); err != nil {
if err = updateMirror(sess, m); err != nil {
log.Error(4, "UpdateMirror [%s]: %v", repoID, err)
continue
}

// Get latest commit date and update to current repository updated time
commitDate, err := git.GetLatestCommitTime(m.Repo.RepoPath())
if err != nil {
log.Error(2, "GetLatestCommitDate [%s]: %v", m.RepoID, err)
continue
}

if _, err = sess.Exec("UPDATE repository SET updated_unix = ? WHERE id = ?", commitDate.Unix(), m.RepoID); err != nil {
log.Error(2, "Update repository 'updated_unix' [%s]: %v", m.RepoID, err)
continue
}
}
}

Expand Down

0 comments on commit 845ba9d

Please sign in to comment.