Browse Source

Merge pull request 'fix 917' (#1070) from fix-917 into V20211213

Reviewed-on: https://git.openi.org.cn/OpenI/aiforge/pulls/1070
Reviewed-by: lewis <747342561@qq.com>
pull/1074/head
lewis 3 years ago
parent
commit
ff61859e79
1 changed files with 18 additions and 0 deletions
  1. +18
    -0
      models/repo.go

+ 18
- 0
models/repo.go View File

@@ -11,6 +11,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"html/template" "html/template"
"xorm.io/xorm"


"code.gitea.io/gitea/modules/blockchain" "code.gitea.io/gitea/modules/blockchain"


@@ -1632,6 +1633,9 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
releaseAttachments = append(releaseAttachments, attachments[i].RelativePath()) releaseAttachments = append(releaseAttachments, attachments[i].RelativePath())
} }


// Delete dataset attachment record and remove related files
deleteDatasetAttachmentByRepoId(sess, repoID)

if err = deleteBeans(sess, if err = deleteBeans(sess,
&Access{RepoID: repo.ID}, &Access{RepoID: repo.ID},
&Action{RepoID: repo.ID}, &Action{RepoID: repo.ID},
@@ -1817,6 +1821,20 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
return nil return nil
} }


func deleteDatasetAttachmentByRepoId(sess *xorm.Session, repoId int64) error {
attachments := make([]*Attachment, 0)
if err := sess.Join("INNER", "dataset", "dataset.id = attachment.dataset_id").
Where("dataset.repo_id = ?", repoId).
Find(&attachments); err != nil {
return err
}
if len(attachments) == 0 {
return nil
}
_, err := DeleteAttachments(attachments, true)
return err
}

// GetRepositoryByOwnerAndName returns the repository by given ownername and reponame. // GetRepositoryByOwnerAndName returns the repository by given ownername and reponame.
func GetRepositoryByOwnerAndName(ownerName, repoName string) (*Repository, error) { func GetRepositoryByOwnerAndName(ownerName, repoName string) (*Repository, error) {
return getRepositoryByOwnerAndName(x, ownerName, repoName) return getRepositoryByOwnerAndName(x, ownerName, repoName)


Loading…
Cancel
Save