diff options
author | Bwko <bouwko@gmail.com> | 2016-12-01 00:56:15 +0100 |
---|---|---|
committer | Kim "BKC" Carlbäcker <kim.carlbacker@gmail.com> | 2016-12-02 07:41:19 +0100 |
commit | 4ff0db0246fa8a2add1032220024975203b93d72 (patch) | |
tree | 6395dd608ba47cc6429bc12d9595f09ebb915f02 /models/user.go | |
parent | 5ab85372da74bd95f7143fd59c2c600d4c9894d0 (diff) | |
download | gitea-4ff0db0246fa8a2add1032220024975203b93d72.tar.gz gitea-4ff0db0246fa8a2add1032220024975203b93d72.zip |
Catch os... errors
Diffstat (limited to 'models/user.go')
-rw-r--r-- | models/user.go | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/models/user.go b/models/user.go index ad20abe24d..41fdf0b024 100644 --- a/models/user.go +++ b/models/user.go @@ -392,7 +392,10 @@ func (u *User) UploadAvatar(data []byte) error { return fmt.Errorf("updateUser: %v", err) } - os.MkdirAll(setting.AvatarUploadPath, os.ModePerm) + if err := os.MkdirAll(setting.AvatarUploadPath, os.ModePerm); err != nil { + return fmt.Errorf("Fail to create dir %s: %v", setting.AvatarUploadPath, err) + } + fw, err := os.Create(u.CustomAvatarPath()) if err != nil { return fmt.Errorf("Create: %v", err) @@ -409,7 +412,10 @@ func (u *User) UploadAvatar(data []byte) error { // DeleteAvatar deletes the user's custom avatar. func (u *User) DeleteAvatar() error { log.Trace("DeleteAvatar[%d]: %s", u.ID, u.CustomAvatarPath()) - os.Remove(u.CustomAvatarPath()) + + if err := os.Remove(u.CustomAvatarPath()); err != nil { + return fmt.Errorf("Fail to remove %s: %v", u.CustomAvatarPath(), err) + } u.UseCustomAvatar = false if err := UpdateUser(u); err != nil { @@ -866,9 +872,16 @@ func deleteUser(e *xorm.Session, u *User) error { // FIXME: system notice // Note: There are something just cannot be roll back, // so just keep error logs of those operations. + path := UserPath(u.Name) - os.RemoveAll(UserPath(u.Name)) - os.Remove(u.CustomAvatarPath()) + if err := os.RemoveAll(path); err != nil { + return fmt.Errorf("Fail to RemoveAll %s: %v", path, err) + } + + avatarPath := u.CustomAvatarPath() + if err := os.Remove(avatarPath); err != nil { + return fmt.Errorf("Fail to remove %s: %v", avatarPath, err) + } return nil } |