@@ -24,7 +24,8 @@ use mime::Mime;
24
24
use path_slash:: PathExt ;
25
25
use serde_with:: { DeserializeFromStr , SerializeDisplay } ;
26
26
use std:: {
27
- fmt, fs,
27
+ fmt,
28
+ fs:: { self , File } ,
28
29
io:: { self , BufReader } ,
29
30
num:: ParseIntError ,
30
31
ops:: RangeInclusive ,
@@ -569,6 +570,33 @@ impl AsyncStorage {
569
570
Ok ( alg)
570
571
}
571
572
573
+ #[ instrument( skip( self ) ) ]
574
+ pub ( crate ) async fn store_path (
575
+ & self ,
576
+ target_path : impl Into < String > + std:: fmt:: Debug ,
577
+ source_path : impl AsRef < Path > + std:: fmt:: Debug ,
578
+ ) -> Result < CompressionAlgorithm > {
579
+ let target_path = target_path. into ( ) ;
580
+ let source_path = source_path. as_ref ( ) ;
581
+
582
+ let alg = CompressionAlgorithm :: default ( ) ;
583
+ let content = compress ( BufReader :: new ( File :: open ( & source_path) ?) , alg) ?;
584
+
585
+ let mime = detect_mime ( & target_path) . to_owned ( ) ;
586
+
587
+ self . store_inner ( vec ! [ Blob {
588
+ path: target_path,
589
+ mime,
590
+ content,
591
+ compression: Some ( alg) ,
592
+ // this field is ignored by the backend
593
+ date_updated: Utc :: now( ) ,
594
+ } ] )
595
+ . await ?;
596
+
597
+ Ok ( alg)
598
+ }
599
+
572
600
async fn store_inner ( & self , batch : Vec < Blob > ) -> Result < ( ) > {
573
601
match & self . backend {
574
602
StorageBackend :: Database ( db) => db. store_batch ( batch) . await ,
@@ -777,6 +805,18 @@ impl Storage {
777
805
self . runtime . block_on ( self . inner . store_one ( path, content) )
778
806
}
779
807
808
+ // Store file into the backend at the given path (also used to detect mime type), returns the
809
+ // chosen compression algorithm
810
+ #[ instrument( skip( self ) ) ]
811
+ pub ( crate ) fn store_path (
812
+ & self ,
813
+ target_path : impl Into < String > + std:: fmt:: Debug ,
814
+ source_path : impl AsRef < Path > + std:: fmt:: Debug ,
815
+ ) -> Result < CompressionAlgorithm > {
816
+ self . runtime
817
+ . block_on ( self . inner . store_path ( target_path, source_path) )
818
+ }
819
+
780
820
/// sync wrapper for the list_prefix function
781
821
/// purely for testing purposes since it collects all files into a Vec.
782
822
#[ cfg( test) ]
@@ -843,7 +883,7 @@ pub(crate) fn rustdoc_json_path(
843
883
format_version : RustdocJsonFormatVersion ,
844
884
) -> String {
845
885
format ! (
846
- "rustdoc-json/{name}/{version}/{target}/{name}_{version}_{target}_{format_version}.json.zst "
886
+ "rustdoc-json/{name}/{version}/{target}/{name}_{version}_{target}_{format_version}.json"
847
887
)
848
888
}
849
889
0 commit comments