Bläddra i källkod

chore: rename `osutil.IsExist` to `osutil.Exist` (#8097)

Copilot 2 veckor sedan
förälder
incheckning
389ec54b2c

+ 1 - 1
internal/cmd/backup.go

@@ -59,7 +59,7 @@ func runBackup(c *cli.Context) error {
 	}
 	}
 
 
 	tmpDir := c.String("tempdir")
 	tmpDir := c.String("tempdir")
-	if !osutil.IsExist(tmpDir) {
+	if !osutil.Exist(tmpDir) {
 		log.Fatal("'--tempdir' does not exist: %s", tmpDir)
 		log.Fatal("'--tempdir' does not exist: %s", tmpDir)
 	}
 	}
 	rootDir, err := os.MkdirTemp(tmpDir, "gogs-backup-")
 	rootDir, err := os.MkdirTemp(tmpDir, "gogs-backup-")

+ 1 - 1
internal/cmd/web.go

@@ -747,7 +747,7 @@ func runWeb(c *cli.Context) error {
 		err = fcgi.Serve(nil, m)
 		err = fcgi.Serve(nil, m)
 
 
 	case "unix":
 	case "unix":
-		if osutil.IsExist(listenAddr) {
+		if osutil.Exist(listenAddr) {
 			err = os.Remove(listenAddr)
 			err = os.Remove(listenAddr)
 			if err != nil {
 			if err != nil {
 				log.Fatal("Failed to remove existing Unix domain socket: %v", err)
 				log.Fatal("Failed to remove existing Unix domain socket: %v", err)

+ 1 - 1
internal/database/public_keys.go

@@ -73,7 +73,7 @@ func (s *PublicKeysStore) RewriteAuthorizedKeys() error {
 	if err != nil {
 	if err != nil {
 		return errors.Wrap(err, "close temporary file")
 		return errors.Wrap(err, "close temporary file")
 	}
 	}
-	if osutil.IsExist(fpath) {
+	if osutil.Exist(fpath) {
 		err = os.Remove(fpath)
 		err = os.Remove(fpath)
 		if err != nil {
 		if err != nil {
 			return errors.Wrap(err, "remove")
 			return errors.Wrap(err, "remove")

+ 1 - 1
internal/database/pull.go

@@ -683,7 +683,7 @@ func (pr *PullRequest) PushToBaseRepo() (err error) {
 
 
 	headRefspec := fmt.Sprintf("refs/pull/%d/head", pr.Index)
 	headRefspec := fmt.Sprintf("refs/pull/%d/head", pr.Index)
 	headFile := filepath.Join(pr.BaseRepo.RepoPath(), headRefspec)
 	headFile := filepath.Join(pr.BaseRepo.RepoPath(), headRefspec)
-	if osutil.IsExist(headFile) {
+	if osutil.Exist(headFile) {
 		err = os.Remove(headFile)
 		err = os.Remove(headFile)
 		if err != nil {
 		if err != nil {
 			return fmt.Errorf("remove head file [repo_id: %d]: %v", pr.BaseRepoID, err)
 			return fmt.Errorf("remove head file [repo_id: %d]: %v", pr.BaseRepoID, err)

+ 2 - 2
internal/database/repo.go

@@ -641,7 +641,7 @@ func (r *Repository) LocalCopyPath() string {
 // assume subsequent operations are against target branch when caller has confidence
 // assume subsequent operations are against target branch when caller has confidence
 // about no race condition.
 // about no race condition.
 func UpdateLocalCopyBranch(repoPath, localPath, branch string, isWiki bool) (err error) {
 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.
 		// Checkout to a specific branch fails when wiki is an empty repository.
 		if isWiki {
 		if isWiki {
 			branch = ""
 			branch = ""
@@ -1200,7 +1200,7 @@ func (err ErrReachLimitOfRepo) Error() string {
 // CreateRepository creates a repository for given user or organization.
 // CreateRepository creates a repository for given user or organization.
 func CreateRepository(doer, owner *User, opts CreateRepoOptionsLegacy) (_ *Repository, err error) {
 func CreateRepository(doer, owner *User, opts CreateRepoOptionsLegacy) (_ *Repository, err error) {
 	repoPath := RepoPath(owner.Name, opts.Name)
 	repoPath := RepoPath(owner.Name, opts.Name)
-	if osutil.IsExist(repoPath) {
+	if osutil.Exist(repoPath) {
 		return nil, errors.Errorf("repository directory already exists: %s", repoPath)
 		return nil, errors.Errorf("repository directory already exists: %s", repoPath)
 	}
 	}
 	if !owner.canCreateRepo() {
 	if !owner.canCreateRepo() {

+ 1 - 1
internal/database/repo_editor.go

@@ -175,7 +175,7 @@ func (r *Repository) UpdateRepoFile(doer *User, opts UpdateRepoFileOptions) erro
 	newFilePath := path.Join(localPath, opts.NewTreeName)
 	newFilePath := path.Join(localPath, opts.NewTreeName)
 
 
 	// Prompt the user if the meant-to-be new file already exists.
 	// 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}
 		return ErrRepoFileAlreadyExist{newFilePath}
 	}
 	}
 
 

+ 1 - 1
internal/database/repo_test.go

@@ -69,5 +69,5 @@ func Test_CreateRepository_PreventDeletion(t *testing.T) {
 	_, err := CreateRepository(owner, owner, opts)
 	_, err := CreateRepository(owner, owner, opts)
 	require.Error(t, err)
 	require.Error(t, err)
 	assert.Contains(t, err.Error(), "repository directory already exists")
 	assert.Contains(t, err.Error(), "repository directory already exists")
-	assert.True(t, osutil.IsExist(canary))
+	assert.True(t, osutil.Exist(canary))
 }
 }

+ 1 - 1
internal/database/users.go

@@ -220,7 +220,7 @@ func (s *UsersStore) ChangeUsername(ctx context.Context, userID int64, newUserna
 
 
 		// Rename user directory if exists
 		// Rename user directory if exists
 		userPath := repoutil.UserPath(user.Name)
 		userPath := repoutil.UserPath(user.Name)
-		if osutil.IsExist(userPath) {
+		if osutil.Exist(userPath) {
 			newUserPath := repoutil.UserPath(newUsername)
 			newUserPath := repoutil.UserPath(newUsername)
 			err = os.Rename(userPath, newUserPath)
 			err = os.Rename(userPath, newUserPath)
 			if err != nil {
 			if err != nil {

+ 11 - 11
internal/database/users_test.go

@@ -325,9 +325,9 @@ func usersChangeUsername(t *testing.T, ctx context.Context, s *UsersStore) {
 	require.NoError(t, err)
 	require.NoError(t, err)
 	assert.Equal(t, int64(0), updatedUnix)
 	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"
 	const newUsername = "alice-new"
 	err = s.ChangeUsername(ctx, alice.ID, newUsername)
 	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)
 	require.NoError(t, err)
 	assert.Equal(t, headUserName, newUsername)
 	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)
 	alice, err = s.GetByID(ctx, alice.ID)
 	require.NoError(t, err)
 	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.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
 	// Pull the trigger
 	err = s.DeleteByID(ctx, testUser.ID, false)
 	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.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)
 	_, err = s.GetByID(ctx, testUser.ID)
 	wantErr := ErrUserNotExist{errutil.Args{"userID": testUser.ID}}
 	wantErr := ErrUserNotExist{errutil.Args{"userID": testUser.ID}}

+ 2 - 2
internal/osutil/osutil.go

@@ -25,8 +25,8 @@ func IsDir(dir string) bool {
 	return f.IsDir()
 	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)
 	_, err := os.Stat(path)
 	return err == nil || os.IsExist(err)
 	return err == nil || os.IsExist(err)
 }
 }

+ 2 - 2
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 {
 	tests := []struct {
 		path   string
 		path   string
 		expVal bool
 		expVal bool
@@ -72,7 +72,7 @@ func TestIsExist(t *testing.T) {
 	}
 	}
 	for _, test := range tests {
 	for _, test := range tests {
 		t.Run("", func(t *testing.T) {
 		t.Run("", func(t *testing.T) {
-			assert.Equal(t, test.expVal, IsExist(test.path))
+			assert.Equal(t, test.expVal, Exist(test.path))
 		})
 		})
 	}
 	}
 }
 }

+ 1 - 1
internal/ssh/ssh.go

@@ -182,7 +182,7 @@ func setupHostKeys(appDataPath string, algorithms []string) ([]ssh.Signer, error
 	var hostKeys []ssh.Signer
 	var hostKeys []ssh.Signer
 	for _, algo := range algorithms {
 	for _, algo := range algorithms {
 		keyPath := filepath.Join(dir, "gogs."+algo)
 		keyPath := filepath.Join(dir, "gogs."+algo)
-		if !osutil.IsExist(keyPath) {
+		if !osutil.Exist(keyPath) {
 			args := []string{
 			args := []string{
 				conf.SSH.KeygenPath,
 				conf.SSH.KeygenPath,
 				"-t", algo,
 				"-t", algo,