@@ -184,67 +184,64 @@ impl<'a> FakeRelease<'a> {
184
184
185
185
/// Returns the release_id
186
186
pub ( crate ) fn create ( self ) -> Result < i32 , Error > {
187
- use std:: collections:: HashSet ;
188
187
use std:: fs;
189
188
use std:: path:: Path ;
190
189
191
190
let tempdir = tempfile:: Builder :: new ( ) . prefix ( "docs.rs-fake" ) . tempdir ( ) ?;
192
191
let package = self . package ;
193
192
let db = self . db ;
193
+ let mut rustdoc_files = self . rustdoc_files ;
194
+ let storage = self . storage ;
194
195
195
- let mut source_meta = None ;
196
- let mut algs = HashSet :: new ( ) ;
197
- if self . build_result . successful {
198
- let storage = self . storage . clone ( ) ;
199
- let upload_files = |prefix : & str , files : & [ ( & str , & [ u8 ] ) ] , target : Option < & str > | {
200
- let mut path_prefix = tempdir. path ( ) . join ( prefix) ;
201
- if let Some ( target) = target {
202
- path_prefix. push ( target) ;
203
- }
204
- fs:: create_dir ( & path_prefix) ?;
205
-
206
- for ( path, data) in files {
207
- // allow `src/main.rs`
208
- if let Some ( parent) = Path :: new ( path) . parent ( ) {
209
- fs:: create_dir_all ( path_prefix. join ( parent) ) ?;
210
- }
211
- let file = path_prefix. join ( & path) ;
212
- log:: debug!( "writing file {}" , file. display( ) ) ;
213
- fs:: write ( file, data) ?;
196
+ // Upload all source files as rustdoc files
197
+ // In real life, these would be highlighted HTML, but for testing we just use the files themselves.
198
+ for ( source_path, data) in & self . source_files {
199
+ if source_path. starts_with ( "src/" ) {
200
+ let updated = [ "src" , & package. name , & source_path[ 4 ..] ] . join ( "/" ) ;
201
+ rustdoc_files. push ( ( Box :: leak ( Box :: new ( updated) ) , data) ) ;
202
+ }
203
+ }
204
+
205
+ let upload_files = |prefix : & str , files : & [ ( & str , & [ u8 ] ) ] , target : Option < & str > | {
206
+ let mut path_prefix = tempdir. path ( ) . join ( prefix) ;
207
+ if let Some ( target) = target {
208
+ path_prefix. push ( target) ;
209
+ }
210
+ fs:: create_dir ( & path_prefix) ?;
211
+
212
+ for ( path, data) in files {
213
+ // allow `src/main.rs`
214
+ if let Some ( parent) = Path :: new ( path) . parent ( ) {
215
+ fs:: create_dir_all ( path_prefix. join ( parent) ) ?;
214
216
}
217
+ let file = path_prefix. join ( & path) ;
218
+ log:: debug!( "writing file {}" , file. display( ) ) ;
219
+ fs:: write ( file, data) ?;
220
+ }
215
221
216
- let prefix = format ! (
217
- "{}/{}/{}/{}" ,
218
- prefix,
219
- package. name,
220
- package. version,
221
- target. unwrap_or( "" )
222
- ) ;
223
- log:: debug!( "adding directory {} from {}" , prefix, path_prefix. display( ) ) ;
224
- crate :: db:: add_path_into_database ( & storage, & prefix, path_prefix)
225
- } ;
222
+ let prefix = format ! (
223
+ "{}/{}/{}/{}" ,
224
+ prefix,
225
+ package. name,
226
+ package. version,
227
+ target. unwrap_or( "" )
228
+ ) ;
229
+ log:: debug!( "adding directory {} from {}" , prefix, path_prefix. display( ) ) ;
230
+ crate :: db:: add_path_into_database ( & storage, & prefix, path_prefix)
231
+ } ;
226
232
233
+ let ( source_meta, mut algs) = upload_files ( "source" , & self . source_files , None ) ?;
234
+ log:: debug!( "added source files {}" , source_meta) ;
235
+
236
+ if self . build_result . successful {
227
237
let index = [ & package. name , "index.html" ] . join ( "/" ) ;
228
- let mut rustdoc_files = self . rustdoc_files ;
229
238
if package. is_library ( ) && !rustdoc_files. iter ( ) . any ( |( path, _) | path == & index) {
230
239
rustdoc_files. push ( ( & index, DEFAULT_CONTENT ) ) ;
231
240
}
232
- for ( source_path, data) in & self . source_files {
233
- if source_path. starts_with ( "src/" ) {
234
- let updated = [ "src" , & package. name , & source_path[ 4 ..] ] . join ( "/" ) ;
235
- rustdoc_files. push ( ( Box :: leak ( Box :: new ( updated) ) , data) ) ;
236
- }
237
- }
241
+
238
242
let ( rustdoc_meta, new_algs) = upload_files ( "rustdoc" , & rustdoc_files, None ) ?;
239
243
algs. extend ( new_algs) ;
240
244
log:: debug!( "added rustdoc files {}" , rustdoc_meta) ;
241
- match upload_files ( "source" , & self . source_files , None ) ? {
242
- ( json, new_algs) => {
243
- source_meta = Some ( json) ;
244
- algs. extend ( new_algs) ;
245
- }
246
- }
247
- log:: debug!( "added source files {}" , source_meta. as_ref( ) . unwrap( ) ) ;
248
245
249
246
for target in & package. targets [ 1 ..] {
250
247
let platform = target. src_path . as_ref ( ) . unwrap ( ) ;
0 commit comments