fix: create directory now ignore conflict error, it will return the existed folder

This commit is contained in:
HFO4
2022-04-21 13:58:22 +08:00
parent 86877aef4b
commit 71df067a76
5 changed files with 21 additions and 32 deletions

View File

@@ -23,11 +23,15 @@ type Folder struct {
// Create 创建目录
func (folder *Folder) Create() (uint, error) {
if err := DB.Create(folder).Error; err != nil {
tx := DB.Begin()
if err := tx.FirstOrCreate(folder, *folder).Error; err != nil {
tx.Rollback()
util.Log().Warning("无法插入目录记录, %s", err)
return 0, err
}
return folder.ID, nil
err := tx.Commit().Error
return folder.ID, err
}
// GetChild 返回folder下名为name的子目录不存在则返回错误