"gitea.com/macaron/session"
archiver "github.com/mholt/archiver/v3"
- "github.com/unknwon/com"
"github.com/urfave/cli"
)
log.Info("Custom dir %s doesn't exist, skipped", setting.CustomPath)
}
- if com.IsExist(setting.AppDataPath) {
+ isExist, err := util.IsExist(setting.AppDataPath)
+ if err != nil {
+ log.Error("Unable to check if %s exists. Error: %v", setting.AppDataPath, err)
+ }
+ if isExist {
log.Info("Packing data directory...%s", setting.AppDataPath)
var excludes []string
// yet or not.
if ctx.IsSet("skip-log") && ctx.Bool("skip-log") {
log.Info("Skip dumping log files")
- } else if com.IsExist(setting.LogRootPath) {
- if err := addRecursive(w, "log", setting.LogRootPath, verbose); err != nil {
- fatal("Failed to include log: %v", err)
+ } else {
+ isExist, err := util.IsExist(setting.LogRootPath)
+ if err != nil {
+ log.Error("Unable to check if %s exists. Error: %v", setting.LogRootPath, err)
+ }
+ if isExist {
+ if err := addRecursive(w, "log", setting.LogRootPath, verbose); err != nil {
+ fatal("Failed to include log: %v", err)
+ }
}
}
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/routers"
"code.gitea.io/gitea/routers/routes"
context2 "github.com/gorilla/context"
- "github.com/unknwon/com"
"github.com/urfave/cli"
"golang.org/x/crypto/acme/autocert"
ini "gopkg.in/ini.v1"
default:
// Save LOCAL_ROOT_URL if port changed
cfg := ini.Empty()
- if com.IsFile(setting.CustomConf) {
+ isFile, err := util.IsFile(setting.CustomConf)
+ if err != nil {
+ log.Fatal("Unable to check if %s is a file", err)
+ }
+ if isFile {
// Keeps custom settings if there is already something.
if err := cfg.Append(setting.CustomConf); err != nil {
return fmt.Errorf("Failed to load custom conf '%s': %v", setting.CustomConf, err)
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/util"
- "github.com/unknwon/com"
"github.com/urfave/cli"
ini "gopkg.in/ini.v1"
)
setting.SetCustomPathAndConf(providedCustom, providedConf, providedWorkPath)
cfg := ini.Empty()
- if com.IsFile(setting.CustomConf) {
+ isFile, err := util.IsFile(setting.CustomConf)
+ if err != nil {
+ log.Fatal("Unable to check if %s is a file. Error: %v", setting.CustomConf, err)
+ }
+ if isFile {
if err := cfg.Append(setting.CustomConf); err != nil {
log.Fatal("Failed to load custom conf '%s': %v", setting.CustomConf, err)
}
if len(destination) == 0 {
destination = setting.CustomConf
}
- err := cfg.SaveTo(destination)
+ err = cfg.SaveTo(destination)
if err != nil {
return err
}
if resp.Code == http.StatusUnprocessableEntity {
respJSON := map[string]string{}
DecodeJSON(t, resp, &respJSON)
- if assert.Equal(t, respJSON["message"], "Remote visit addressed rate limitation.") {
+ if assert.Equal(t, "Remote visit addressed rate limitation.", respJSON["message"]) {
t.Log("test hit github rate limitation")
}
} else {
log.Fatal("Failed to get %s files: %v", t, err)
}
customPath := path.Join(setting.CustomPath, "options", t)
- if com.IsDir(customPath) {
+ isDir, err := util.IsDir(customPath)
+ if err != nil {
+ log.Fatal("Failed to get custom %s files: %v", t, err)
+ }
+ if isDir {
customFiles, err := com.StatDir(customPath)
if err != nil {
log.Fatal("Failed to get custom %s files: %v", t, err)
OwnerID: u.ID,
LowerName: strings.ToLower(repoName),
})
- return has && com.IsDir(RepoPath(u.Name, repoName)), err
+ if err != nil {
+ return false, err
+ }
+ isDir, err := util.IsDir(RepoPath(u.Name, repoName))
+ return has && isDir, err
}
// IsRepositoryExist returns true if the repository with given name under user has already existed.
return ErrRepoAlreadyExist{u.Name, name}
}
- if !overwriteOrAdopt && com.IsExist(RepoPath(u.Name, name)) {
+ isExist, err := util.IsExist(RepoPath(u.Name, name))
+ if err != nil {
+ log.Error("Unable to check if %s exists. Error: %v", RepoPath(u.Name, name), err)
+ return err
+ }
+ if !overwriteOrAdopt && isExist {
return ErrRepoFilesAlreadyExist{u.Name, name}
}
return nil
// Use custom file when available.
customPath := path.Join(setting.CustomPath, relPath)
- if com.IsFile(customPath) {
+ isFile, err := util.IsFile(customPath)
+ if err != nil {
+ log.Error("Unable to check if %s is a file. Error: %v", customPath, err)
+ }
+ if isFile {
return ioutil.ReadFile(customPath)
}
}
repoPath := RepoPath(u.Name, repo.Name)
- if !overwriteOrAdopt && com.IsExist(repoPath) {
+ isExist, err := util.IsExist(repoPath)
+ if err != nil {
+ log.Error("Unable to check if %s exists. Error: %v", repoPath, err)
+ return err
+ }
+ if !overwriteOrAdopt && isExist {
log.Error("Files already exist in %s and we are not going to adopt or delete.", repoPath)
return ErrRepoFilesAlreadyExist{
Uname: u.Name,
// Rename remote wiki repository to new path and delete local copy.
wikiPath := WikiPath(oldOwner.Name, repo.Name)
- if com.IsExist(wikiPath) {
+ isExist, err := util.IsExist(wikiPath)
+ if err != nil {
+ log.Error("Unable to check if %s exists. Error: %v", wikiPath, err)
+ return err
+ }
+ if isExist {
if err = os.Rename(wikiPath, WikiPath(newOwner.Name, repo.Name)); err != nil {
return fmt.Errorf("rename repository wiki: %v", err)
}
}
wikiPath := repo.WikiPath()
- if com.IsExist(wikiPath) {
+ isExist, err := util.IsExist(wikiPath)
+ if err != nil {
+ log.Error("Unable to check if %s exists. Error: %v", wikiPath, err)
+ return err
+ }
+ if isExist {
if err = os.Rename(wikiPath, WikiPath(repo.Owner.Name, newRepoName)); err != nil {
return fmt.Errorf("rename repository wiki: %v", err)
}
// Create/Remove git-daemon-export-ok for git-daemon...
daemonExportFile := path.Join(repo.RepoPath(), `git-daemon-export-ok`)
- if repo.IsPrivate && com.IsExist(daemonExportFile) {
+ isExist, err := util.IsExist(daemonExportFile)
+ if err != nil {
+ log.Error("Unable to check if %s exists. Error: %v", daemonExportFile, err)
+ return err
+ }
+ if repo.IsPrivate && isExist {
if err = util.Remove(daemonExportFile); err != nil {
log.Error("Failed to remove %s: %v", daemonExportFile, err)
}
- } else if !repo.IsPrivate && !com.IsExist(daemonExportFile) {
+ } else if !repo.IsPrivate && !isExist {
if f, err := os.Create(daemonExportFile); err != nil {
log.Error("Failed to create %s: %v", daemonExportFile, err)
} else {
}
}()
- if setting.SSH.AuthorizedKeysBackup && com.IsExist(fPath) {
- bakPath := fmt.Sprintf("%s_%d.gitea_bak", fPath, time.Now().Unix())
- if err = com.Copy(fPath, bakPath); err != nil {
+ if setting.SSH.AuthorizedKeysBackup {
+ isExist, err := util.IsExist(fPath)
+ if err != nil {
+ log.Error("Unable to check if %s exists. Error: %v", fPath, err)
return err
}
+ if isExist {
+ bakPath := fmt.Sprintf("%s_%d.gitea_bak", fPath, time.Now().Unix())
+ if err = com.Copy(fPath, bakPath); err != nil {
+ return err
+ }
+ }
}
if err := regeneratePublicKeys(e, t); err != nil {
}
fPath := filepath.Join(setting.SSH.RootPath, "authorized_keys")
- if com.IsExist(fPath) {
+ isExist, err := util.IsExist(fPath)
+ if err != nil {
+ log.Error("Unable to check if %s exists. Error: %v", fPath, err)
+ return err
+ }
+ if isExist {
f, err := os.Open(fPath)
if err != nil {
return err
os.Remove(tmpPath)
}()
- if setting.SSH.AuthorizedPrincipalsBackup && com.IsExist(fPath) {
- bakPath := fmt.Sprintf("%s_%d.gitea_bak", fPath, time.Now().Unix())
- if err = com.Copy(fPath, bakPath); err != nil {
+ if setting.SSH.AuthorizedPrincipalsBackup {
+ isExist, err := util.IsExist(fPath)
+ if err != nil {
+ log.Error("Unable to check if %s exists. Error: %v", fPath, err)
return err
}
+ if isExist {
+ bakPath := fmt.Sprintf("%s_%d.gitea_bak", fPath, time.Now().Unix())
+ if err = com.Copy(fPath, bakPath); err != nil {
+ return err
+ }
+ }
}
if err := regeneratePrincipalKeys(e, t); err != nil {
}
fPath := filepath.Join(setting.SSH.RootPath, authorizedPrincipalsFile)
- if com.IsExist(fPath) {
+ isExist, err := util.IsExist(fPath)
+ if err != nil {
+ log.Error("Unable to check if %s exists. Error: %v", fPath, err)
+ return err
+ }
+ if isExist {
f, err := os.Open(fPath)
if err != nil {
return err
"os"
"path"
+ "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
gouuid "github.com/google/uuid"
- "github.com/unknwon/com"
)
// ____ ___ .__ .___ ___________.___.__
for _, upload := range uploads {
localPath := upload.LocalPath()
- if !com.IsFile(localPath) {
+ isFile, err := util.IsFile(localPath)
+ if err != nil {
+ log.Error("Unable to check if %s is a file. Error: %v", localPath, err)
+ }
+ if !isFile {
continue
}
"path/filepath"
"strings"
- "github.com/unknwon/com"
+ "code.gitea.io/gitea/modules/log"
+ "code.gitea.io/gitea/modules/util"
)
// WikiCloneLink returns clone URLs of repository wiki.
// HasWiki returns true if repository has wiki.
func (repo *Repository) HasWiki() bool {
- return com.IsDir(repo.WikiPath())
+ isDir, err := util.IsDir(repo.WikiPath())
+ if err != nil {
+ log.Error("Unable to check if %s is a directory: %v", repo.WikiPath(), err)
+ }
+ return isDir
}
"strings"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs"
+ "code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/routers/utils"
"gitea.com/macaron/binding"
"gitea.com/macaron/macaron"
- "github.com/unknwon/com"
)
// _______________________________________ _________.______________________ _______________.___.
}
} else if !user.CanImportLocal() {
return "", models.ErrInvalidCloneAddr{IsPermissionDenied: true}
- } else if !com.IsDir(remoteAddr) {
- return "", models.ErrInvalidCloneAddr{IsInvalidPath: true}
+ } else {
+ isDir, err := util.IsDir(remoteAddr)
+ if err != nil {
+ log.Error("Unable to check if %s is a directory: %v", remoteAddr, err)
+ return "", err
+ }
+ if !isDir {
+ return "", models.ErrInvalidCloneAddr{IsInvalidPath: true}
+ }
}
return remoteAddr, nil
"strings"
"code.gitea.io/gitea/modules/util"
- "github.com/unknwon/com"
)
// hookNames is a list of Git server hooks' name that are supported.
func SetUpdateHook(repoPath, content string) (err error) {
log("Setting update hook: %s", repoPath)
hookPath := path.Join(repoPath, HookPathUpdate)
- if com.IsExist(hookPath) {
+ isExist, err := util.IsExist(hookPath)
+ if err != nil {
+ log("Unable to check if %s exists. Error: %v", hookPath, err)
+ return err
+ }
+ if isExist {
err = util.Remove(hookPath)
} else {
err = os.MkdirAll(path.Dir(hookPath), os.ModePerm)
"io/ioutil"
"path"
+ "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/util"
"github.com/unknwon/com"
)
customDir := path.Join(setting.CustomPath, "options", name)
- if com.IsDir(customDir) {
+ isDir, err := util.IsDir(customDir)
+ if err != nil {
+ return []string{}, fmt.Errorf("Unabe to check if custom directory %s is a directory. %v", customDir, err)
+ }
+ if isDir {
files, err := com.StatDir(customDir, true)
if err != nil {
staticDir := path.Join(setting.StaticRootPath, "options", name)
- if com.IsDir(staticDir) {
+ isDir, err = util.IsDir(staticDir)
+ if err != nil {
+ return []string{}, fmt.Errorf("Unabe to check if static directory %s is a directory. %v", staticDir, err)
+ }
+ if isDir {
files, err := com.StatDir(staticDir, true)
if err != nil {
func fileFromDir(name string) ([]byte, error) {
customPath := path.Join(setting.CustomPath, "options", name)
- if com.IsFile(customPath) {
+ isFile, err := util.IsFile(customPath)
+ if err != nil {
+ log.Error("Unable to check if %s is a file. Error: %v", customPath, err)
+ }
+ if isFile {
return ioutil.ReadFile(customPath)
}
staticPath := path.Join(setting.StaticRootPath, "options", name)
- if com.IsFile(staticPath) {
+ isFile, err = util.IsFile(staticPath)
+ if err != nil {
+ log.Error("Unable to check if %s is a file. Error: %v", staticPath, err)
+ }
+ if isFile {
return ioutil.ReadFile(staticPath)
}
"io/ioutil"
"path"
+ "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/util"
"github.com/unknwon/com"
)
)
customDir := path.Join(setting.CustomPath, "options", name)
-
- if com.IsDir(customDir) {
+ isDir, err := util.IsDir(customDir)
+ if err != nil {
+ return []string{}, fmt.Errorf("Failed to check if custom directory %s is a directory. %v", err)
+ }
+ if isDir {
files, err := com.StatDir(customDir, true)
if err != nil {
func fileFromDir(name string) ([]byte, error) {
customPath := path.Join(setting.CustomPath, "options", name)
- if com.IsFile(customPath) {
+ isFile, err := util.IsFile(customPath)
+ if err != nil {
+ log.Error("Unable to check if %s is a file. Error: %v", customPath, err)
+ }
+ if isFile {
return ioutil.ReadFile(customPath)
}
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"github.com/gobwas/glob"
- "github.com/unknwon/com"
)
// AdoptRepository adopts a repository for the user/organization.
if err := models.WithTx(func(ctx models.DBContext) error {
repoPath := models.RepoPath(u.Name, repo.Name)
- if !com.IsExist(repoPath) {
+ isExist, err := util.IsExist(repoPath)
+ if err != nil {
+ log.Error("Unable to check if %s exists. Error: %v", repoPath, err)
+ return err
+ }
+ if !isExist {
return models.ErrRepoNotExist{
OwnerName: u.Name,
Name: repo.Name,
}
repoPath := models.RepoPath(u.Name, repoName)
- if !com.IsExist(repoPath) {
+ isExist, err := util.IsExist(repoPath)
+ if err != nil {
+ log.Error("Unable to check if %s exists. Error: %v", repoPath, err)
+ return err
+ }
+ if !isExist {
return models.ErrRepoNotExist{
OwnerName: u.Name,
Name: repoName,
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
+ "code.gitea.io/gitea/modules/util"
- "github.com/unknwon/com"
"xorm.io/builder"
)
return models.ErrCancelledf("during gathering missing repo records before checking %s", repo.FullName())
default:
}
- if !com.IsDir(repo.RepoPath()) {
+ isDir, err := util.IsDir(repo.RepoPath())
+ if err != nil {
+ return fmt.Errorf("Unable to check dir for %s. %w", repo.FullName(), err)
+ }
+ if !isDir {
repos = append(repos, repo)
}
return nil
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
-
- "github.com/unknwon/com"
)
// CreateRepository creates a repository for the user/organization.
}
repoPath := models.RepoPath(u.Name, repo.Name)
- if com.IsExist(repoPath) {
+ isExist, err := util.IsExist(repoPath)
+ if err != nil {
+ log.Error("Unable to check if %s exists. Error: %v", repoPath, err)
+ return err
+ }
+ if isExist {
// repo already exists - We have two or three options.
// 1. We fail stating that the directory exists
// 2. We create the db repository to go with this data and adopt the git repo
"code.gitea.io/gitea/modules/util"
"github.com/huandu/xstrings"
- "github.com/unknwon/com"
)
type transformer struct {
}
repoPath := generateRepo.RepoPath()
- if com.IsExist(repoPath) {
+ isExist, err := util.IsExist(repoPath)
+ if err != nil {
+ log.Error("Unable to check if %s exists. Error: %v", repoPath, err)
+ return nil, err
+ }
+ if isExist {
return nil, models.ErrRepoFilesAlreadyExist{
Uname: generateRepo.OwnerName,
Name: generateRepo.Name,
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
- "github.com/unknwon/com"
"xorm.io/builder"
)
newHookPath := filepath.Join(hookDir, hookName+".d", "gitea")
cont := false
- if !com.IsExist(oldHookPath) {
+ isExist, err := util.IsExist(oldHookPath)
+ if err != nil {
+ results = append(results, fmt.Sprintf("unable to check if %s exists. Error: %v", oldHookPath, err))
+ }
+ if err == nil && !isExist {
results = append(results, fmt.Sprintf("old hook file %s does not exist", oldHookPath))
cont = true
}
- if !com.IsExist(oldHookPath + ".d") {
+ isExist, err = util.IsExist(oldHookPath + ".d")
+ if err != nil {
+ results = append(results, fmt.Sprintf("unable to check if %s exists. Error: %v", oldHookPath+".d", err))
+ }
+ if err == nil && !isExist {
results = append(results, fmt.Sprintf("hooks directory %s does not exist", oldHookPath+".d"))
cont = true
}
- if !com.IsExist(newHookPath) {
+ isExist, err = util.IsExist(newHookPath)
+ if err != nil {
+ results = append(results, fmt.Sprintf("unable to check if %s exists. Error: %v", newHookPath, err))
+ }
+ if err == nil && !isExist {
results = append(results, fmt.Sprintf("new hook file %s does not exist", newHookPath))
cont = true
}
func checkInitRepository(owner, name string) (err error) {
// Somehow the directory could exist.
repoPath := models.RepoPath(owner, name)
- if com.IsExist(repoPath) {
+ isExist, err := util.IsExist(repoPath)
+ if err != nil {
+ log.Error("Unable to check if %s exists. Error: %v", repoPath, err)
+ return err
+ }
+ if isExist {
return models.ErrRepoFilesAlreadyExist{
Uname: owner,
Name: name,
}
func adoptRepository(ctx models.DBContext, repoPath string, u *models.User, repo *models.Repository, opts models.CreateRepoOptions) (err error) {
- if !com.IsExist(repoPath) {
+ isExist, err := util.IsExist(repoPath)
+ if err != nil {
+ log.Error("Unable to check if %s exists. Error: %v", repoPath, err)
+ return err
+ }
+ if !isExist {
return fmt.Errorf("adoptRepository: path does not already exist: %s", repoPath)
}
"code.gitea.io/gitea/modules/generate"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
+ "code.gitea.io/gitea/modules/util"
- "github.com/unknwon/com"
ini "gopkg.in/ini.v1"
)
// Save secret
cfg := ini.Empty()
- if com.IsFile(CustomConf) {
+ isFile, err := util.IsFile(CustomConf)
+ if err != nil {
+ log.Error("Unable to check if %s is a file. Error: %v", CustomConf, err)
+ }
+ if isFile {
// Keeps custom settings if there is already something.
if err := cfg.Append(CustomConf); err != nil {
log.Error("Failed to load custom conf '%s': %v", CustomConf, err)
"code.gitea.io/gitea/modules/generate"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/user"
+ "code.gitea.io/gitea/modules/util"
shellquote "github.com/kballard/go-shellquote"
"github.com/unknwon/com"
createPIDFile(PIDFile)
}
- if com.IsFile(CustomConf) {
+ isFile, err := util.IsFile(CustomConf)
+ if err != nil {
+ log.Error("Unable to check if %s is a file. Error: %v", CustomConf, err)
+ }
+ if isFile {
if err := Cfg.Append(CustomConf); err != nil {
log.Fatal("Failed to load custom conf '%s': %v", CustomConf, err)
}
return
}
cfg := ini.Empty()
- if com.IsFile(CustomConf) {
+ isFile, err := util.IsFile(CustomConf)
+ if err != nil {
+ log.Error("Unable to check if %s is a file. Error: %v", CustomConf, err)
+ }
+ if isFile {
if err := cfg.Append(CustomConf); err != nil {
log.Error("failed to load custom conf %s: %v", CustomConf, err)
return
UI.SearchRepoDescription = Cfg.Section("ui").Key("SEARCH_REPO_DESCRIPTION").MustBool(true)
UI.UseServiceWorker = Cfg.Section("ui").Key("USE_SERVICE_WORKER").MustBool(true)
- HasRobotsTxt = com.IsFile(path.Join(CustomPath, "robots.txt"))
+ HasRobotsTxt, err = util.IsFile(path.Join(CustomPath, "robots.txt"))
+ if err != nil {
+ log.Error("Unable to check if %s is a file. Error: %v", path.Join(CustomPath, "robots.txt"), err)
+ }
newMarkup()
// Save secret
cfgSave := ini.Empty()
- if com.IsFile(CustomConf) {
+ isFile, err := util.IsFile(CustomConf)
+ if err != nil {
+ log.Error("Unable to check if %s is a file. Error: %v", CustomConf, err)
+ }
+ if isFile {
// Keeps custom settings if there is already something.
if err := cfgSave.Append(CustomConf); err != nil {
log.Error("Failed to load custom conf '%s': %v", CustomConf, err)
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/util"
"github.com/gliderlabs/ssh"
"github.com/unknwon/com"
}
keyPath := filepath.Join(setting.AppDataPath, "ssh/gogs.rsa")
- if !com.IsExist(keyPath) {
+ isExist, err := util.IsExist(keyPath)
+ if err != nil {
+ log.Fatal("Unable to check if %s exists. Error: %v", keyPath, err)
+ }
+ if !isExist {
filePath := filepath.Dir(keyPath)
if err := os.MkdirAll(filePath, os.ModePerm); err != nil {
log.Trace("New private key is generated: %s", keyPath)
}
- err := srv.SetOption(ssh.HostKeyFile(keyPath))
+ err = srv.SetOption(ssh.HostKeyFile(keyPath))
if err != nil {
log.Error("Failed to set Host Key. %s", err)
}
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/util"
"gitea.com/macaron/macaron"
"github.com/unknwon/com"
staticDir := path.Join(setting.StaticRootPath, "templates", "mail")
- if com.IsDir(staticDir) {
+ isDir, err := util.IsDir(staticDir)
+ if err != nil {
+ log.Warn("Unable to check if templates dir %s is a directory. Error: %v", staticDir, err)
+ }
+ if isDir {
files, err := com.StatDir(staticDir)
if err != nil {
customDir := path.Join(setting.CustomPath, "templates", "mail")
- if com.IsDir(customDir) {
+ isDir, err = util.IsDir(customDir)
+ if err != nil {
+ log.Warn("Unable to check if templates dir %s is a directory. Error: %v", customDir, err)
+ }
+ if isDir {
files, err := com.StatDir(customDir)
if err != nil {
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/util"
"gitea.com/macaron/macaron"
"github.com/unknwon/com"
}
customDir := path.Join(setting.CustomPath, "templates")
-
- if com.IsDir(customDir) {
+ isDir, err := util.IsDir(customDir)
+ if err != nil {
+ log.Warn("Unable to check if templates dir %s is a directory. Error: %v", customDir, err)
+ }
+ if isDir {
files, err := com.StatDir(customDir)
if err != nil {
}
customDir := path.Join(setting.CustomPath, "templates", "mail")
-
- if com.IsDir(customDir) {
+ isDir, err := util.IsDir(customDir)
+ if err != nil {
+ log.Warn("Failed to check if custom directory %s is a directory. %v", err)
+ }
+ if isDir {
files, err := com.StatDir(customDir)
if err != nil {
})
return size, err
}
+
+// IsDir returns true if given path is a directory,
+// or returns false when it's a file or does not exist.
+func IsDir(dir string) (bool, error) {
+ f, err := os.Stat(dir)
+ if err == nil {
+ return f.IsDir(), nil
+ }
+ if os.IsNotExist(err) {
+ return false, nil
+ }
+ return false, err
+}
+
+// IsFile returns true if given path is a file,
+// or returns false when it's a directory or does not exist.
+func IsFile(filePath string) (bool, error) {
+ f, err := os.Stat(filePath)
+ if err == nil {
+ return !f.IsDir(), nil
+ }
+ if os.IsNotExist(err) {
+ return false, nil
+ }
+ return false, err
+}
+
+// IsExist checks whether a file or directory exists.
+// It returns false when the file or directory does not exist.
+func IsExist(path string) (bool, error) {
+ _, err := os.Stat(path)
+ if err == nil || os.IsExist(err) {
+ return true, nil
+ }
+ if os.IsNotExist(err) {
+ return false, nil
+ }
+ return false, err
+}
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/routers"
repo_service "code.gitea.io/gitea/services/repository"
- "github.com/unknwon/com"
)
const (
repoName := dirSplit[1]
// check not a repo
- if has, err := models.IsRepositoryExist(ctxUser, repoName); err != nil {
+ has, err := models.IsRepositoryExist(ctxUser, repoName)
+ if err != nil {
ctx.ServerError("IsRepositoryExist", err)
return
- } else if has || !com.IsDir(models.RepoPath(ctxUser.Name, repoName)) {
+ }
+ isDir, err := util.IsDir(models.RepoPath(ctxUser.Name, repoName))
+ if err != nil {
+ ctx.ServerError("IsDir", err)
+ return
+ }
+ if has || !isDir {
// Fallthrough to failure mode
} else if action == "adopt" {
if _, err := repository.AdoptRepository(ctx.User, ctxUser, models.CreateRepoOptions{
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/repository"
+ "code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/routers/api/v1/utils"
- "github.com/unknwon/com"
)
// ListUnadoptedRepositories lists the unadopted repositories that match the provided names
}
// check not a repo
- if has, err := models.IsRepositoryExist(ctxUser, repoName); err != nil {
+ has, err := models.IsRepositoryExist(ctxUser, repoName)
+ if err != nil {
+ ctx.InternalServerError(err)
+ return
+ }
+ isDir, err := util.IsDir(models.RepoPath(ctxUser.Name, repoName))
+ if err != nil {
ctx.InternalServerError(err)
return
- } else if has || !com.IsDir(models.RepoPath(ctxUser.Name, repoName)) {
+ }
+ if has || !isDir {
ctx.NotFound()
return
}
}
// check not a repo
- if has, err := models.IsRepositoryExist(ctxUser, repoName); err != nil {
+ has, err := models.IsRepositoryExist(ctxUser, repoName)
+ if err != nil {
+ ctx.InternalServerError(err)
+ return
+ }
+ isDir, err := util.IsDir(models.RepoPath(ctxUser.Name, repoName))
+ if err != nil {
ctx.InternalServerError(err)
return
- } else if has || !com.IsDir(models.RepoPath(ctxUser.Name, repoName)) {
+ }
+ if has || !isDir {
ctx.NotFound()
return
}
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/user"
+ "code.gitea.io/gitea/modules/util"
"github.com/unknwon/com"
"gopkg.in/ini.v1"
// Save settings.
cfg := ini.Empty()
- if com.IsFile(setting.CustomConf) {
+ isFile, err := util.IsFile(setting.CustomConf)
+ if err != nil {
+ log.Error("Unable to check if %s is a file. Error: %v", setting.CustomConf, err)
+ }
+ if isFile {
// Keeps custom settings if there is already something.
if err = cfg.Append(setting.CustomConf); err != nil {
log.Error("Failed to load custom conf '%s': %v", setting.CustomConf, err)
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
- "github.com/unknwon/com"
+ "code.gitea.io/gitea/modules/util"
)
// AdoptOrDeleteRepository adopts or deletes a repository
root := filepath.Join(models.UserPath(ctxUser.LowerName))
// check not a repo
- if has, err := models.IsRepositoryExist(ctxUser, dir); err != nil {
+ has, err := models.IsRepositoryExist(ctxUser, dir)
+ if err != nil {
ctx.ServerError("IsRepositoryExist", err)
return
- } else if has || !com.IsDir(filepath.Join(root, dir+".git")) {
+ }
+
+ isDir, err := util.IsDir(filepath.Join(root, dir+".git"))
+ if err != nil {
+ ctx.ServerError("IsDir", err)
+ return
+ }
+ if has || !isDir {
// Fallthrough to failure mode
} else if action == "adopt" && allowAdopt {
if _, err := repository.AdoptRepository(ctxUser, ctxUser, models.CreateRepoOptions{
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
-
- "github.com/unknwon/com"
+ "code.gitea.io/gitea/modules/util"
)
// ArchiveRequest defines the parameters of an archive request, which notably
}
r.refName = strings.TrimSuffix(r.uri, r.ext)
- if !com.IsDir(r.archivePath) {
+ isDir, err := util.IsDir(r.archivePath)
+ if err != nil {
+ ctx.ServerError("Download -> util.IsDir(archivePath)", err)
+ return nil
+ }
+ if !isDir {
if err := os.MkdirAll(r.archivePath, os.ModePerm); err != nil {
ctx.ServerError("Download -> os.MkdirAll(archivePath)", err)
return nil
}
// Get corresponding commit.
- var (
- err error
- )
if r.repo.IsBranchExist(r.refName) {
r.commit, err = r.repo.GetBranchCommit(r.refName)
if err != nil {
}
r.archivePath = path.Join(r.archivePath, base.ShortSha(r.commit.ID.String())+r.ext)
- r.archiveComplete = com.IsFile(r.archivePath)
+ r.archiveComplete, err = util.IsFile(r.archivePath)
+ if err != nil {
+ ctx.ServerError("util.IsFile", err)
+ return nil
+ }
return r
}
// race conditions and difficulties in locking. Do one last check that
// the archive we're referring to doesn't already exist. If it does exist,
// then just mark the request as complete and move on.
- if com.IsFile(r.archivePath) {
+ isFile, err := util.IsFile(r.archivePath)
+ if err != nil {
+ log.Error("Unable to check if %s util.IsFile: %v. Will ignore and recreate.", r.archivePath, err)
+ }
+ if isFile {
r.archiveComplete = true
return
}