@@ -74,7 +74,11 @@ func loadRepoConfig() {
7474 log .Fatal ("Failed to get %s files: %v" , t , err )
7575 }
7676 customPath := path .Join (setting .CustomPath , "options" , t )
77- if com .IsDir (customPath ) {
77+ isDir , err := util .IsDir (customPath )
78+ if err != nil {
79+ log .Fatal ("Failed to get custom %s files: %v" , t , err )
80+ }
81+ if isDir {
7882 customFiles , err := com .StatDir (customPath )
7983 if err != nil {
8084 log .Fatal ("Failed to get custom %s files: %v" , t , err )
@@ -1004,7 +1008,11 @@ func isRepositoryExist(e Engine, u *User, repoName string) (bool, error) {
10041008 OwnerID : u .ID ,
10051009 LowerName : strings .ToLower (repoName ),
10061010 })
1007- return has && com .IsDir (RepoPath (u .Name , repoName )), err
1011+ if err != nil {
1012+ return false , err
1013+ }
1014+ isDir , err := util .IsDir (RepoPath (u .Name , repoName ))
1015+ return has && isDir , err
10081016}
10091017
10101018// IsRepositoryExist returns true if the repository with given name under user has already existed.
@@ -1078,7 +1086,12 @@ func CheckCreateRepository(doer, u *User, name string, overwriteOrAdopt bool) er
10781086 return ErrRepoAlreadyExist {u .Name , name }
10791087 }
10801088
1081- if ! overwriteOrAdopt && com .IsExist (RepoPath (u .Name , name )) {
1089+ isExist , err := util .IsExist (RepoPath (u .Name , name ))
1090+ if err != nil {
1091+ log .Error ("Unable to check if %s exists. Error: %v" , RepoPath (u .Name , name ), err )
1092+ return err
1093+ }
1094+ if ! overwriteOrAdopt && isExist {
10821095 return ErrRepoFilesAlreadyExist {u .Name , name }
10831096 }
10841097 return nil
@@ -1110,7 +1123,11 @@ func GetRepoInitFile(tp, name string) ([]byte, error) {
11101123
11111124 // Use custom file when available.
11121125 customPath := path .Join (setting .CustomPath , relPath )
1113- if com .IsFile (customPath ) {
1126+ isFile , err := util .IsFile (customPath )
1127+ if err != nil {
1128+ log .Error ("Unable to check if %s is a file. Error: %v" , customPath , err )
1129+ }
1130+ if isFile {
11141131 return ioutil .ReadFile (customPath )
11151132 }
11161133
@@ -1156,7 +1173,12 @@ func CreateRepository(ctx DBContext, doer, u *User, repo *Repository, overwriteO
11561173 }
11571174
11581175 repoPath := RepoPath (u .Name , repo .Name )
1159- if ! overwriteOrAdopt && com .IsExist (repoPath ) {
1176+ isExist , err := util .IsExist (repoPath )
1177+ if err != nil {
1178+ log .Error ("Unable to check if %s exists. Error: %v" , repoPath , err )
1179+ return err
1180+ }
1181+ if ! overwriteOrAdopt && isExist {
11601182 log .Error ("Files already exist in %s and we are not going to adopt or delete." , repoPath )
11611183 return ErrRepoFilesAlreadyExist {
11621184 Uname : u .Name ,
@@ -1408,7 +1430,12 @@ func TransferOwnership(doer *User, newOwnerName string, repo *Repository) error
14081430
14091431 // Rename remote wiki repository to new path and delete local copy.
14101432 wikiPath := WikiPath (oldOwner .Name , repo .Name )
1411- if com .IsExist (wikiPath ) {
1433+ isExist , err := util .IsExist (wikiPath )
1434+ if err != nil {
1435+ log .Error ("Unable to check if %s exists. Error: %v" , wikiPath , err )
1436+ return err
1437+ }
1438+ if isExist {
14121439 if err = os .Rename (wikiPath , WikiPath (newOwner .Name , repo .Name )); err != nil {
14131440 return fmt .Errorf ("rename repository wiki: %v" , err )
14141441 }
@@ -1451,7 +1478,12 @@ func ChangeRepositoryName(doer *User, repo *Repository, newRepoName string) (err
14511478 }
14521479
14531480 wikiPath := repo .WikiPath ()
1454- if com .IsExist (wikiPath ) {
1481+ isExist , err := util .IsExist (wikiPath )
1482+ if err != nil {
1483+ log .Error ("Unable to check if %s exists. Error: %v" , wikiPath , err )
1484+ return err
1485+ }
1486+ if isExist {
14551487 if err = os .Rename (wikiPath , WikiPath (repo .Owner .Name , newRepoName )); err != nil {
14561488 return fmt .Errorf ("rename repository wiki: %v" , err )
14571489 }
@@ -1528,11 +1560,16 @@ func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err e
15281560
15291561 // Create/Remove git-daemon-export-ok for git-daemon...
15301562 daemonExportFile := path .Join (repo .RepoPath (), `git-daemon-export-ok` )
1531- if repo .IsPrivate && com .IsExist (daemonExportFile ) {
1563+ isExist , err := util .IsExist (daemonExportFile )
1564+ if err != nil {
1565+ log .Error ("Unable to check if %s exists. Error: %v" , daemonExportFile , err )
1566+ return err
1567+ }
1568+ if repo .IsPrivate && isExist {
15321569 if err = util .Remove (daemonExportFile ); err != nil {
15331570 log .Error ("Failed to remove %s: %v" , daemonExportFile , err )
15341571 }
1535- } else if ! repo .IsPrivate && ! com . IsExist ( daemonExportFile ) {
1572+ } else if ! repo .IsPrivate && ! isExist {
15361573 if f , err := os .Create (daemonExportFile ); err != nil {
15371574 log .Error ("Failed to create %s: %v" , daemonExportFile , err )
15381575 } else {
0 commit comments