diff options
Diffstat (limited to 'models/repo.go')
-rw-r--r-- | models/repo.go | 59 |
1 files changed, 33 insertions, 26 deletions
diff --git a/models/repo.go b/models/repo.go index efd78c6042..25b1e65206 100644 --- a/models/repo.go +++ b/models/repo.go @@ -1146,16 +1146,6 @@ func CreateRepository(ctx context.Context, doer, u *User, repo *Repository, over return fmt.Errorf("recalculateAccesses: %v", err) } - if u.Visibility == api.VisibleTypePublic && !repo.IsPrivate { - // Create/Remove git-daemon-export-ok for git-daemon... - daemonExportFile := path.Join(repo.RepoPath(), `git-daemon-export-ok`) - if f, err := os.Create(daemonExportFile); err != nil { - log.Error("Failed to create %s: %v", daemonExportFile, err) - } else { - f.Close() - } - } - if setting.Service.AutoWatchNewRepos { if err = watchRepo(db.GetEngine(ctx), doer.ID, repo.ID, true); err != nil { return fmt.Errorf("watchRepo: %v", err) @@ -1169,6 +1159,38 @@ func CreateRepository(ctx context.Context, doer, u *User, repo *Repository, over return nil } +// CheckDaemonExportOK creates/removes git-daemon-export-ok for git-daemon... +func (repo *Repository) CheckDaemonExportOK(ctx context.Context) error { + e := db.GetEngine(ctx) + if err := repo.getOwner(e); err != nil { + return err + } + + // Create/Remove git-daemon-export-ok for git-daemon... + daemonExportFile := path.Join(repo.RepoPath(), `git-daemon-export-ok`) + + isExist, err := util.IsExist(daemonExportFile) + if err != nil { + log.Error("Unable to check if %s exists. Error: %v", daemonExportFile, err) + return err + } + + isPublic := !repo.IsPrivate && repo.Owner.Visibility == api.VisibleTypePublic + if !isPublic && isExist { + if err = util.Remove(daemonExportFile); err != nil { + log.Error("Failed to remove %s: %v", daemonExportFile, err) + } + } else if isPublic && !isExist { + if f, err := os.Create(daemonExportFile); err != nil { + log.Error("Failed to create %s: %v", daemonExportFile, err) + } else { + f.Close() + } + } + + return nil +} + func countRepositories(userID int64, private bool) int64 { sess := db.GetEngine(db.DefaultContext).Where("id > 0") @@ -1318,24 +1340,9 @@ func updateRepository(e db.Engine, repo *Repository, visibilityChanged bool) (er } // Create/Remove git-daemon-export-ok for git-daemon... - daemonExportFile := path.Join(repo.RepoPath(), `git-daemon-export-ok`) - isExist, err := util.IsExist(daemonExportFile) - isPublic := !repo.IsPrivate && repo.Owner.Visibility == api.VisibleTypePublic - if err != nil { - log.Error("Unable to check if %s exists. Error: %v", daemonExportFile, err) + if err := repo.CheckDaemonExportOK(db.WithEngine(db.DefaultContext, e)); err != nil { return err } - if !isPublic && isExist { - if err = util.Remove(daemonExportFile); err != nil { - log.Error("Failed to remove %s: %v", daemonExportFile, err) - } - } else if isPublic && !isExist { - if f, err := os.Create(daemonExportFile); err != nil { - log.Error("Failed to create %s: %v", daemonExportFile, err) - } else { - f.Close() - } - } forkRepos, err := getRepositoriesByForkID(e, repo.ID) if err != nil { |