@@ -7,10 +7,12 @@ use anyhow::Context as _;
77use fn_error_context:: context;
88use sqlx:: Connection ;
99
10+ use super :: update_latest_version_id;
11+
1012/// List of directories in docs.rs's underlying storage (either the database or S3) containing a
1113/// subdirectory named after the crate. Those subdirectories will be deleted.
1214static LIBRARY_STORAGE_PATHS_TO_DELETE : & [ & str ] = & [ "rustdoc" , "sources" ] ;
13- static BINARY_STORAGE_PATHS_TO_DELETE : & [ & str ] = & [ "sources" ] ;
15+ static OTHER_STORAGE_PATHS_TO_DELETE : & [ & str ] = & [ "sources" ] ;
1416
1517#[ derive( Debug , thiserror:: Error ) ]
1618enum CrateDeletionError {
@@ -31,7 +33,7 @@ pub async fn delete_crate(
3133 let paths = if is_library {
3234 LIBRARY_STORAGE_PATHS_TO_DELETE
3335 } else {
34- BINARY_STORAGE_PATHS_TO_DELETE
36+ OTHER_STORAGE_PATHS_TO_DELETE
3537 } ;
3638
3739 for prefix in paths {
@@ -69,7 +71,7 @@ pub async fn delete_version(
6971 let paths = if is_library {
7072 LIBRARY_STORAGE_PATHS_TO_DELETE
7173 } else {
72- BINARY_STORAGE_PATHS_TO_DELETE
74+ OTHER_STORAGE_PATHS_TO_DELETE
7375 } ;
7476
7577 for prefix in paths {
@@ -139,23 +141,15 @@ async fn delete_version_from_database(
139141 version,
140142 )
141143 . fetch_one ( & mut * transaction)
142- . await ?;
144+ . await ?
145+ . unwrap_or ( false ) ;
143146
144- sqlx:: query!(
145- "UPDATE crates SET latest_version_id = (
146- SELECT id FROM releases WHERE release_time = (
147- SELECT MAX(release_time) FROM releases WHERE crate_id = $1
148- )
149- ) WHERE id = $1" ,
150- crate_id,
151- )
152- . execute ( & mut * transaction)
153- . await ?;
147+ update_latest_version_id ( & mut transaction, crate_id) . await ?;
154148
155149 let paths = if is_library {
156150 LIBRARY_STORAGE_PATHS_TO_DELETE
157151 } else {
158- BINARY_STORAGE_PATHS_TO_DELETE
152+ OTHER_STORAGE_PATHS_TO_DELETE
159153 } ;
160154 for prefix in paths {
161155 sqlx:: query!(
@@ -221,7 +215,7 @@ async fn delete_crate_from_database(
221215mod tests {
222216 use super :: * ;
223217 use crate :: registry_api:: { CrateOwner , OwnerKind } ;
224- use crate :: test:: { assert_success , wrapper } ;
218+ use crate :: test:: async_wrapper ;
225219 use test_case:: test_case;
226220
227221 async fn crate_exists ( conn : & mut sqlx:: PgConnection , name : & str ) -> Result < bool > {
0 commit comments