@@ -82,6 +82,7 @@ pub fn start_jsonrpc_server() {
8282 handlers. add_request_handler ( "resolve" , handle_resolve) ;
8383 handlers. add_request_handler ( "find" , handle_find) ;
8484 handlers. add_request_handler ( "condaInfo" , handle_conda_telemetry) ;
85+ handlers. add_request_handler ( "clearCache" , handle_clear_cache) ;
8586 start_server ( & handlers)
8687}
8788
@@ -112,7 +113,8 @@ pub fn handle_configure(context: Arc<Context>, id: u32, params: Value) {
112113 // We will not support changing the cache directories once set.
113114 // No point, supporting such a use case.
114115 if let Some ( cache_directory) = configure_options. cache_directory {
115- set_cache_directory ( cache_directory)
116+ set_cache_directory ( cache_directory. clone ( ) ) ;
117+ cfg. cache_directory = Some ( cache_directory) ;
116118 }
117119 trace ! ( "Configuring locators: {:?}" , cfg) ;
118120 drop ( cfg) ;
@@ -381,3 +383,29 @@ pub fn handle_conda_telemetry(context: Arc<Context>, id: u32, _params: Value) {
381383 send_reply ( id, info. into ( ) ) ;
382384 } ) ;
383385}
386+
387+ pub fn handle_clear_cache ( context : Arc < Context > , id : u32 , _params : Value ) {
388+ thread:: spawn ( move || {
389+ if let Some ( cache_directory) = context
390+ . configuration
391+ . read ( )
392+ . unwrap ( )
393+ . cache_directory
394+ . clone ( )
395+ {
396+ if let Err ( e) = std:: fs:: remove_dir_all ( & cache_directory) {
397+ error ! ( "Failed to clear cache {:?}: {}" , cache_directory, e) ;
398+ send_error (
399+ Some ( id) ,
400+ -4 ,
401+ format ! ( "Failed to clear cache {:?}: {}" , cache_directory, e) ,
402+ ) ;
403+ } else {
404+ info ! ( "Cleared cache {:?}" , cache_directory) ;
405+ send_reply ( id, None :: < ( ) > ) ;
406+ }
407+ } else {
408+ send_reply ( id, None :: < ( ) > ) ;
409+ }
410+ } ) ;
411+ }
0 commit comments