mirror of
https://github.com/gogs/gogs.git
synced 2026-02-12 01:17:03 +01:00
chore: rename osutil.IsExist to osutil.Exist (#8097)
This commit is contained in:
@@ -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-")
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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}
|
||||
}
|
||||
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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}}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user