@@ -3,7 +3,7 @@ use std::{collections::HashMap, path::PathBuf, sync::Arc};
33use semver:: Version ;
44use serde:: { Deserialize , Serialize } ;
55use time:: OffsetDateTime ;
6- use tokio:: sync:: RwLock ;
6+ use tokio:: { fs , sync:: RwLock } ;
77
88#[ derive( Debug , Clone , Serialize , Deserialize ) ]
99struct Fetch {
@@ -47,12 +47,13 @@ impl CrateCache {
4747 cache
4848 }
4949 pub async fn change_directory ( & self , directory : PathBuf ) {
50- std :: fs:: create_dir_all ( & directory) . unwrap_or_else ( |_| {
50+ fs:: create_dir_all ( & directory) . await . unwrap_or_else ( |_| {
5151 panic ! ( "Failed to create crates-lsp cache directory: {directory:?}" )
5252 } ) ;
5353
5454 // This directory might be within a git repository, so make sure it is ignored.
55- std:: fs:: write ( directory. join ( ".gitignore" ) , "*" )
55+ fs:: write ( directory. join ( ".gitignore" ) , "*" )
56+ . await
5657 . expect ( "failed to create crates-lsp .gitignore file." ) ;
5758
5859 * self . directory . write ( ) . await = directory
@@ -68,7 +69,8 @@ impl CrateCache {
6869 } ;
6970
7071 // Attempt to load crate informtion from file cache.
71- if let Ok ( content) = std:: fs:: read_to_string ( self . directory . read ( ) . await . join ( crate_name) ) {
72+ if let Ok ( content) = fs:: read_to_string ( self . directory . read ( ) . await . join ( crate_name) ) . await
73+ {
7274 if let Ok ( fetch) = serde_json:: from_str :: < Fetch > ( & content) {
7375 if OffsetDateTime :: now_utc ( ) < fetch. expires_at {
7476 self . put ( crate_name, fetch. version . clone ( ) , fetch. expires_at )
@@ -93,10 +95,11 @@ impl CrateCache {
9395 expires_at,
9496 } ;
9597
96- std :: fs:: write (
98+ fs:: write (
9799 self . directory . read ( ) . await . join ( crate_name) ,
98100 serde_json:: to_string ( & fetch) . as_deref ( ) . unwrap_or ( "{}" ) ,
99101 )
102+ . await
100103 . unwrap ( ) ;
101104
102105 self . crates
0 commit comments