summaryrefslogtreecommitdiffstats
path: root/models/repo_editor.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_editor.go
parent5ab85372da74bd95f7143fd59c2c600d4c9894d0 (diff)
downloadgitea-4ff0db0246fa8a2add1032220024975203b93d72.tar.gz
gitea-4ff0db0246fa8a2add1032220024975203b93d72.zip
Catch os... errors
Diffstat (limited to 'models/repo_editor.go')
-rw-r--r--models/repo_editor.go18
1 files changed, 15 insertions, 3 deletions
diff --git a/models/repo_editor.go b/models/repo_editor.go
index 0d821f9f8c..b8bd46bc1d 100644
--- a/models/repo_editor.go
+++ b/models/repo_editor.go
@@ -104,7 +104,11 @@ func (repo *Repository) UpdateRepoFile(doer *User, opts UpdateRepoFileOptions) (
localPath := repo.LocalCopyPath()
oldFilePath := path.Join(localPath, opts.OldTreeName)
filePath := path.Join(localPath, opts.NewTreeName)
- os.MkdirAll(path.Dir(filePath), os.ModePerm)
+ dir := path.Dir(filePath)
+
+ if err := os.MkdirAll(dir, os.ModePerm); err != nil {
+ return fmt.Errorf("Fail to create dir %s: %v", dir, err)
+ }
// If it's meant to be a new file, make sure it doesn't exist.
if opts.IsNewFile {
@@ -185,7 +189,12 @@ func (repo *Repository) GetDiffPreview(branch, treePath, content string) (diff *
localPath := repo.LocalCopyPath()
filePath := path.Join(localPath, treePath)
- os.MkdirAll(filepath.Dir(filePath), os.ModePerm)
+ dir := filepath.Dir(filePath)
+
+ if err := os.MkdirAll(dir, os.ModePerm); err != nil {
+ return nil, fmt.Errorf("Fail to create dir %s: %v", dir, err)
+ }
+
if err = ioutil.WriteFile(filePath, []byte(content), 0666); err != nil {
return nil, fmt.Errorf("WriteFile: %v", err)
}
@@ -475,7 +484,10 @@ func (repo *Repository) UploadRepoFiles(doer *User, opts UploadRepoFileOptions)
localPath := repo.LocalCopyPath()
dirPath := path.Join(localPath, opts.TreePath)
- os.MkdirAll(dirPath, os.ModePerm)
+
+ if err := os.MkdirAll(dirPath, os.ModePerm); err != nil {
+ return fmt.Errorf("Fail to create dir %s: %v", dirPath, err)
+ }
// Copy uploaded files into repository.
for _, upload := range uploads {