From 389ec54b2c73e87fc9d6b3c7620b7be22122ac40 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Wed, 21 Jan 2026 22:22:07 -0500 Subject: [PATCH] chore: rename `osutil.IsExist` to `osutil.Exist` (#8097) --- internal/cmd/backup.go | 2 +- internal/cmd/web.go | 2 +- internal/database/public_keys.go | 2 +- internal/database/pull.go | 2 +- internal/database/repo.go | 4 ++-- internal/database/repo_editor.go | 2 +- internal/database/repo_test.go | 2 +- internal/database/users.go | 2 +- internal/database/users_test.go | 22 +++++++++++----------- internal/osutil/osutil.go | 4 ++-- internal/osutil/osutil_test.go | 4 ++-- internal/ssh/ssh.go | 2 +- 12 files changed, 25 insertions(+), 25 deletions(-) diff --git a/internal/cmd/backup.go b/internal/cmd/backup.go index 4de6cb247..174194566 100644 --- a/internal/cmd/backup.go +++ b/internal/cmd/backup.go @@ -59,7 +59,7 @@ func runBackup(c *cli.Context) error { } tmpDir := c.String("tempdir") - if !osutil.IsExist(tmpDir) { + if !osutil.Exist(tmpDir) { log.Fatal("'--tempdir' does not exist: %s", tmpDir) } rootDir, err := os.MkdirTemp(tmpDir, "gogs-backup-") diff --git a/internal/cmd/web.go b/internal/cmd/web.go index fae34ddd3..caf616be6 100644 --- a/internal/cmd/web.go +++ b/internal/cmd/web.go @@ -747,7 +747,7 @@ func runWeb(c *cli.Context) error { err = fcgi.Serve(nil, m) case "unix": - if osutil.IsExist(listenAddr) { + if osutil.Exist(listenAddr) { err = os.Remove(listenAddr) if err != nil { log.Fatal("Failed to remove existing Unix domain socket: %v", err) diff --git a/internal/database/public_keys.go b/internal/database/public_keys.go index 98fb7eafd..93b212a6a 100644 --- a/internal/database/public_keys.go +++ b/internal/database/public_keys.go @@ -73,7 +73,7 @@ func (s *PublicKeysStore) RewriteAuthorizedKeys() error { if err != nil { return errors.Wrap(err, "close temporary file") } - if osutil.IsExist(fpath) { + if osutil.Exist(fpath) { err = os.Remove(fpath) if err != nil { return errors.Wrap(err, "remove") diff --git a/internal/database/pull.go b/internal/database/pull.go index 70256cf88..1b4f7f5cf 100644 --- a/internal/database/pull.go +++ b/internal/database/pull.go @@ -683,7 +683,7 @@ func (pr *PullRequest) PushToBaseRepo() (err error) { headRefspec := fmt.Sprintf("refs/pull/%d/head", pr.Index) headFile := filepath.Join(pr.BaseRepo.RepoPath(), headRefspec) - if osutil.IsExist(headFile) { + if osutil.Exist(headFile) { err = os.Remove(headFile) if err != nil { return fmt.Errorf("remove head file [repo_id: %d]: %v", pr.BaseRepoID, err) diff --git a/internal/database/repo.go b/internal/database/repo.go index e90161ca6..0a9d4da6a 100644 --- a/internal/database/repo.go +++ b/internal/database/repo.go @@ -641,7 +641,7 @@ func (r *Repository) LocalCopyPath() string { // assume subsequent operations are against target branch when caller has confidence // about no race condition. func UpdateLocalCopyBranch(repoPath, localPath, branch string, isWiki bool) (err error) { - if !osutil.IsExist(localPath) { + if !osutil.Exist(localPath) { // Checkout to a specific branch fails when wiki is an empty repository. if isWiki { branch = "" @@ -1200,7 +1200,7 @@ func (err ErrReachLimitOfRepo) Error() string { // CreateRepository creates a repository for given user or organization. func CreateRepository(doer, owner *User, opts CreateRepoOptionsLegacy) (_ *Repository, err error) { repoPath := RepoPath(owner.Name, opts.Name) - if osutil.IsExist(repoPath) { + if osutil.Exist(repoPath) { return nil, errors.Errorf("repository directory already exists: %s", repoPath) } if !owner.canCreateRepo() { diff --git a/internal/database/repo_editor.go b/internal/database/repo_editor.go index 4f874165f..8878b51d6 100644 --- a/internal/database/repo_editor.go +++ b/internal/database/repo_editor.go @@ -175,7 +175,7 @@ func (r *Repository) UpdateRepoFile(doer *User, opts UpdateRepoFileOptions) erro newFilePath := path.Join(localPath, opts.NewTreeName) // Prompt the user if the meant-to-be new file already exists. - if osutil.IsExist(newFilePath) && opts.IsNewFile { + if osutil.Exist(newFilePath) && opts.IsNewFile { return ErrRepoFileAlreadyExist{newFilePath} } diff --git a/internal/database/repo_test.go b/internal/database/repo_test.go index d8c15264b..e5d6f43bf 100644 --- a/internal/database/repo_test.go +++ b/internal/database/repo_test.go @@ -69,5 +69,5 @@ func Test_CreateRepository_PreventDeletion(t *testing.T) { _, err := CreateRepository(owner, owner, opts) require.Error(t, err) assert.Contains(t, err.Error(), "repository directory already exists") - assert.True(t, osutil.IsExist(canary)) + assert.True(t, osutil.Exist(canary)) } diff --git a/internal/database/users.go b/internal/database/users.go index 5e0cd03bf..aabfc5c5e 100644 --- a/internal/database/users.go +++ b/internal/database/users.go @@ -220,7 +220,7 @@ func (s *UsersStore) ChangeUsername(ctx context.Context, userID int64, newUserna // Rename user directory if exists userPath := repoutil.UserPath(user.Name) - if osutil.IsExist(userPath) { + if osutil.Exist(userPath) { newUserPath := repoutil.UserPath(newUsername) err = os.Rename(userPath, newUserPath) if err != nil { diff --git a/internal/database/users_test.go b/internal/database/users_test.go index e6279e2dd..9ed6fdfaf 100644 --- a/internal/database/users_test.go +++ b/internal/database/users_test.go @@ -325,9 +325,9 @@ func usersChangeUsername(t *testing.T, ctx context.Context, s *UsersStore) { require.NoError(t, err) assert.Equal(t, int64(0), updatedUnix) - assert.True(t, osutil.IsExist(repoutil.UserPath(alice.Name))) - assert.True(t, osutil.IsExist(repoutil.RepositoryLocalPath(repo.ID))) - assert.True(t, osutil.IsExist(repoutil.RepositoryLocalWikiPath(repo.ID))) + assert.True(t, osutil.Exist(repoutil.UserPath(alice.Name))) + assert.True(t, osutil.Exist(repoutil.RepositoryLocalPath(repo.ID))) + assert.True(t, osutil.Exist(repoutil.RepositoryLocalWikiPath(repo.ID))) const newUsername = "alice-new" err = s.ChangeUsername(ctx, alice.ID, newUsername) @@ -338,10 +338,10 @@ func usersChangeUsername(t *testing.T, ctx context.Context, s *UsersStore) { require.NoError(t, err) assert.Equal(t, headUserName, newUsername) - assert.True(t, osutil.IsExist(repoutil.UserPath(newUsername))) - assert.False(t, osutil.IsExist(repoutil.UserPath(alice.Name))) - assert.False(t, osutil.IsExist(repoutil.RepositoryLocalPath(repo.ID))) - assert.False(t, osutil.IsExist(repoutil.RepositoryLocalWikiPath(repo.ID))) + assert.True(t, osutil.Exist(repoutil.UserPath(newUsername))) + assert.False(t, osutil.Exist(repoutil.UserPath(alice.Name))) + assert.False(t, osutil.Exist(repoutil.RepositoryLocalPath(repo.ID))) + assert.False(t, osutil.Exist(repoutil.RepositoryLocalWikiPath(repo.ID))) alice, err = s.GetByID(ctx, alice.ID) require.NoError(t, err) @@ -616,8 +616,8 @@ func usersDeleteByID(t *testing.T, ctx context.Context, s *UsersStore) { assert.NotZero(t, count, "table for %T", table) } - assert.True(t, osutil.IsExist(tempUserPath)) - assert.True(t, osutil.IsExist(tempCustomAvatarPath)) + assert.True(t, osutil.Exist(tempUserPath)) + assert.True(t, osutil.Exist(tempCustomAvatarPath)) // Pull the trigger err = s.DeleteByID(ctx, testUser.ID, false) @@ -663,8 +663,8 @@ func usersDeleteByID(t *testing.T, ctx context.Context, s *UsersStore) { assert.Equal(t, int64(0), count, "table for %T", table) } - assert.False(t, osutil.IsExist(tempUserPath)) - assert.False(t, osutil.IsExist(tempCustomAvatarPath)) + assert.False(t, osutil.Exist(tempUserPath)) + assert.False(t, osutil.Exist(tempCustomAvatarPath)) _, err = s.GetByID(ctx, testUser.ID) wantErr := ErrUserNotExist{errutil.Args{"userID": testUser.ID}} diff --git a/internal/osutil/osutil.go b/internal/osutil/osutil.go index fe62f3535..34dd90f9e 100644 --- a/internal/osutil/osutil.go +++ b/internal/osutil/osutil.go @@ -25,8 +25,8 @@ func IsDir(dir string) bool { return f.IsDir() } -// IsExist returns true if a file or directory exists following any symlinks. -func IsExist(path string) bool { +// Exist returns true if a file or directory exists following any symlinks. +func Exist(path string) bool { _, err := os.Stat(path) return err == nil || os.IsExist(err) } diff --git a/internal/osutil/osutil_test.go b/internal/osutil/osutil_test.go index 924954785..60262d119 100644 --- a/internal/osutil/osutil_test.go +++ b/internal/osutil/osutil_test.go @@ -54,7 +54,7 @@ func TestIsDir(t *testing.T) { } } -func TestIsExist(t *testing.T) { +func TestExist(t *testing.T) { tests := []struct { path string expVal bool @@ -72,7 +72,7 @@ func TestIsExist(t *testing.T) { } for _, test := range tests { t.Run("", func(t *testing.T) { - assert.Equal(t, test.expVal, IsExist(test.path)) + assert.Equal(t, test.expVal, Exist(test.path)) }) } } diff --git a/internal/ssh/ssh.go b/internal/ssh/ssh.go index 017c947d4..898d235be 100644 --- a/internal/ssh/ssh.go +++ b/internal/ssh/ssh.go @@ -182,7 +182,7 @@ func setupHostKeys(appDataPath string, algorithms []string) ([]ssh.Signer, error var hostKeys []ssh.Signer for _, algo := range algorithms { keyPath := filepath.Join(dir, "gogs."+algo) - if !osutil.IsExist(keyPath) { + if !osutil.Exist(keyPath) { args := []string{ conf.SSH.KeygenPath, "-t", algo,