@@ -1992,6 +1992,17 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
1992
1992
}
1993
1993
}
1994
1994
1995
+ releaseAttachments := make ([]string , 0 , 20 )
1996
+ attachments := make ([]* Attachment , 0 , len (releaseAttachments ))
1997
+ if err = sess .Join ("INNER" , "release" , "release.id = attachment.release_id" ).
1998
+ Where ("release.repo_id = ?" , repoID ).
1999
+ Find (& attachments ); err != nil {
2000
+ return err
2001
+ }
2002
+ for i := 0 ; i < len (attachments ); i ++ {
2003
+ releaseAttachments = append (releaseAttachments , attachments [i ].LocalPath ())
2004
+ }
2005
+
1995
2006
if err = deleteBeans (sess ,
1996
2007
& Access {RepoID : repo .ID },
1997
2008
& Action {RepoID : repo .ID },
@@ -2043,7 +2054,7 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
2043
2054
}
2044
2055
2045
2056
attachmentPaths := make ([]string , 0 , 20 )
2046
- attachments : = make ([]* Attachment , 0 , len (attachmentPaths ))
2057
+ attachments = make ([]* Attachment , 0 , len (attachmentPaths ))
2047
2058
if err = sess .Join ("INNER" , "issue" , "issue.id = attachment.issue_id" ).
2048
2059
Where ("issue.repo_id = ?" , repoID ).
2049
2060
Find (& attachments ); err != nil {
@@ -2085,11 +2096,6 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
2085
2096
return err
2086
2097
}
2087
2098
2088
- // Remove attachment files.
2089
- for i := range attachmentPaths {
2090
- removeAllWithNotice (sess , "Delete attachment" , attachmentPaths [i ])
2091
- }
2092
-
2093
2099
// Remove LFS objects
2094
2100
var lfsObjects []* LFSMetaObject
2095
2101
if err = sess .Where ("repository_id=?" , repoID ).Find (& lfsObjects ); err != nil {
@@ -2129,6 +2135,23 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
2129
2135
return fmt .Errorf ("Commit: %v" , err )
2130
2136
}
2131
2137
2138
+ sess .Close ()
2139
+
2140
+ // We should always delete the files after the database transaction succeed. If
2141
+ // we delete the file but the database rollback, the repository will be borken.
2142
+
2143
+ // Remove issue attachment files.
2144
+ for i := range attachmentPaths {
2145
+ removeAllWithNotice (x , "Delete issue attachment" , attachmentPaths [i ])
2146
+ }
2147
+
2148
+ // Remove release attachment files.
2149
+ if len (releaseAttachments ) > 0 {
2150
+ for i := range releaseAttachments {
2151
+ removeAllWithNotice (x , "Delete release attachment" , releaseAttachments [i ])
2152
+ }
2153
+ }
2154
+
2132
2155
if len (repo .Avatar ) > 0 {
2133
2156
avatarPath := repo .CustomAvatarPath ()
2134
2157
if com .IsExist (avatarPath ) {
0 commit comments