@@ -1992,6 +1992,17 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
1992
1992
}
1993
1993
}
1994
1994
1995
+ attachments := make ([]* Attachment , 0 , 20 )
1996
+ if err = sess .Join ("INNER" , "`release`" , "`release`.id = `attachment`.release_id" ).
1997
+ Where ("`release`.repo_id = ?" , repoID ).
1998
+ Find (& attachments ); err != nil {
1999
+ return err
2000
+ }
2001
+ releaseAttachments := make ([]string , 0 , len (attachments ))
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 },
@@ -2042,13 +2053,13 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
2042
2053
return err
2043
2054
}
2044
2055
2045
- attachmentPaths := make ([]string , 0 , 20 )
2046
- attachments := make ([]* Attachment , 0 , len (attachmentPaths ))
2056
+ attachments = attachments [:0 ]
2047
2057
if err = sess .Join ("INNER" , "issue" , "issue.id = attachment.issue_id" ).
2048
2058
Where ("issue.repo_id = ?" , repoID ).
2049
2059
Find (& attachments ); err != nil {
2050
2060
return err
2051
2061
}
2062
+ attachmentPaths := make ([]string , 0 , len (attachments ))
2052
2063
for j := range attachments {
2053
2064
attachmentPaths = append (attachmentPaths , attachments [j ].LocalPath ())
2054
2065
}
@@ -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,21 @@ 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
+ for i := range releaseAttachments {
2150
+ removeAllWithNotice (x , "Delete release attachment" , releaseAttachments [i ])
2151
+ }
2152
+
2132
2153
if len (repo .Avatar ) > 0 {
2133
2154
avatarPath := repo .CustomAvatarPath ()
2134
2155
if com .IsExist (avatarPath ) {
0 commit comments