@@ -33,14 +33,26 @@ import (
33
33
34
34
// DeleteRepository deletes a repository for a user or organization.
35
35
// make sure if you call this func to close open sessions (sqlite will otherwise get a deadlock)
36
- func DeleteRepositoryDirectly (ctx context.Context , doer * user_model.User , uid , repoID int64 ) error {
36
+ func DeleteRepositoryDirectly (ctx context.Context , doer * user_model.User , repoID int64 ) error {
37
37
ctx , committer , err := db .TxContext (ctx )
38
38
if err != nil {
39
39
return err
40
40
}
41
41
defer committer .Close ()
42
42
sess := db .GetEngine (ctx )
43
43
44
+ repo := & repo_model.Repository {}
45
+ has , err := sess .ID (repoID ).Get (repo )
46
+ if err != nil {
47
+ return err
48
+ } else if ! has {
49
+ return repo_model.ErrRepoNotExist {
50
+ ID : repoID ,
51
+ OwnerName : "" ,
52
+ Name : "" ,
53
+ }
54
+ }
55
+
44
56
// Query the action tasks of this repo, they will be needed after they have been deleted to remove the logs
45
57
tasks , err := actions_model .FindTasks (ctx , actions_model.FindTaskOptions {RepoID : repoID })
46
58
if err != nil {
@@ -54,24 +66,11 @@ func DeleteRepositoryDirectly(ctx context.Context, doer *user_model.User, uid, r
54
66
}
55
67
56
68
// In case is a organization.
57
- org , err := user_model .GetUserByID (ctx , uid )
69
+ org , err := user_model .GetUserByID (ctx , repo . OwnerID )
58
70
if err != nil {
59
71
return err
60
72
}
61
73
62
- repo := & repo_model.Repository {OwnerID : uid }
63
- has , err := sess .ID (repoID ).Get (repo )
64
- if err != nil {
65
- return err
66
- } else if ! has {
67
- return repo_model.ErrRepoNotExist {
68
- ID : repoID ,
69
- UID : uid ,
70
- OwnerName : "" ,
71
- Name : "" ,
72
- }
73
- }
74
-
75
74
// Delete Deploy Keys
76
75
deployKeys , err := asymkey_model .ListDeployKeys (ctx , & asymkey_model.ListDeployKeysOptions {RepoID : repoID })
77
76
if err != nil {
@@ -89,7 +88,6 @@ func DeleteRepositoryDirectly(ctx context.Context, doer *user_model.User, uid, r
89
88
} else if cnt != 1 {
90
89
return repo_model.ErrRepoNotExist {
91
90
ID : repoID ,
92
- UID : uid ,
93
91
OwnerName : "" ,
94
92
Name : "" ,
95
93
}
@@ -192,7 +190,7 @@ func DeleteRepositoryDirectly(ctx context.Context, doer *user_model.User, uid, r
192
190
}
193
191
}
194
192
195
- if _ , err := db .Exec (ctx , "UPDATE `user` SET num_repos=num_repos-1 WHERE id=?" , uid ); err != nil {
193
+ if _ , err := db .Exec (ctx , "UPDATE `user` SET num_repos=num_repos-1 WHERE id=?" , repo . OwnerID ); err != nil {
196
194
return err
197
195
}
198
196
0 commit comments