summaryrefslogtreecommitdiffstats
path: root/models/repo.go
diff options
context:
space:
mode:
authorBwko <bouwko@gmail.com>2016-12-01 00:56:15 +0100
committerKim "BKC" Carlbäcker <kim.carlbacker@gmail.com>2016-12-02 07:41:19 +0100
commit4ff0db0246fa8a2add1032220024975203b93d72 (patch)
tree6395dd608ba47cc6429bc12d9595f09ebb915f02 /models/repo.go
parent5ab85372da74bd95f7143fd59c2c600d4c9894d0 (diff)
downloadgitea-4ff0db0246fa8a2add1032220024975203b93d72.tar.gz
gitea-4ff0db0246fa8a2add1032220024975203b93d72.zip
Catch os... errors
Diffstat (limited to 'models/repo.go')
-rw-r--r--models/repo.go30
1 files changed, 25 insertions, 5 deletions
diff --git a/models/repo.go b/models/repo.go
index d86956eeb5..af74e6c8fc 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -558,8 +558,12 @@ func (repo *Repository) SavePatch(index int64, patch []byte) error {
if err != nil {
return fmt.Errorf("PatchPath: %v", err)
}
+ dir := filepath.Dir(patchPath)
+
+ if err := os.MkdirAll(dir, os.ModePerm); err != nil {
+ return fmt.Errorf("Fail to create dir %s: %v", dir, err)
+ }
- os.MkdirAll(filepath.Dir(patchPath), os.ModePerm)
if err = ioutil.WriteFile(patchPath, patch, 0644); err != nil {
return fmt.Errorf("WriteFile: %v", err)
}
@@ -669,7 +673,10 @@ func MigrateRepository(u *User, opts MigrateRepoOptions) (*Repository, error) {
migrateTimeout := time.Duration(setting.Git.Timeout.Migrate) * time.Second
- os.RemoveAll(repoPath)
+ if err := os.RemoveAll(repoPath); err != nil {
+ return repo, fmt.Errorf("Fail to remove %s: %v", repoPath, err)
+ }
+
if err = git.Clone(opts.RemoteAddr, repoPath, git.CloneRepoOptions{
Mirror: true,
Quiet: true,
@@ -680,7 +687,11 @@ func MigrateRepository(u *User, opts MigrateRepoOptions) (*Repository, error) {
wikiRemotePath := wikiRemoteURL(opts.RemoteAddr)
if len(wikiRemotePath) > 0 {
- os.RemoveAll(wikiPath)
+
+ if err := os.RemoveAll(wikiPath); err != nil {
+ return repo, fmt.Errorf("Fail to remove %s: %v", wikiPath, err)
+ }
+
if err = git.Clone(wikiRemotePath, wikiPath, git.CloneRepoOptions{
Mirror: true,
Quiet: true,
@@ -902,7 +913,11 @@ func initRepository(e Engine, repoPath string, u *User, repo *Repository, opts C
// Initialize repository according to user's choice.
if opts.AutoInit {
- os.MkdirAll(tmpDir, os.ModePerm)
+
+ if err := os.MkdirAll(tmpDir, os.ModePerm); err != nil {
+ return fmt.Errorf("Fail to create dir %s: %v", tmpDir, err)
+ }
+
defer os.RemoveAll(tmpDir)
if err = prepareRepoCommit(repo, tmpDir, repoPath, opts); err != nil {
@@ -1198,7 +1213,12 @@ func TransferOwnership(doer *User, newOwnerName string, repo *Repository) error
}
// Rename remote repository to new path and delete local copy.
- os.MkdirAll(UserPath(newOwner.Name), os.ModePerm)
+ dir := UserPath(newOwner.Name)
+
+ if err := os.MkdirAll(dir, os.ModePerm); err != nil {
+ return fmt.Errorf("Fail to create dir %s: %v", dir, err)
+ }
+
if err = os.Rename(RepoPath(owner.Name, repo.Name), RepoPath(newOwner.Name, repo.Name)); err != nil {
return fmt.Errorf("rename repository directory: %v", err)
}