浏览代码

models/user: better directory handling when change username

Previously, if the user base directory somehow doesn't exist, the
application throws 500 for failure of rename.

Now it detects if the application should rename or just create a
new directory.
Unknwon 8 年之前
父节点
当前提交
bb005f3f9a
共有 1 个文件被更改,包括 7 次插入1 次删除
  1. 7 1
      models/user.go

+ 7 - 1
models/user.go

@@ -682,7 +682,13 @@ func ChangeUserName(u *User, newUserName string) (err error) {
 		return fmt.Errorf("Delete repository wiki local copy: %v", err)
 	}
 
-	return os.Rename(UserPath(u.Name), UserPath(newUserName))
+	// Rename or create user base directory
+	baseDir := UserPath(u.Name)
+	newBaseDir := UserPath(newUserName)
+	if com.IsExist(baseDir) {
+		return os.Rename(baseDir, newBaseDir)
+	}
+	return os.MkdirAll(newBaseDir, os.ModePerm)
 }
 
 func updateUser(e Engine, u *User) error {