@@ -6,13 +6,13 @@ use hyper::rt::Future;
66use hyper:: service:: service_fn;
77use hyper:: { Body , Method , Request , Response , Server , StatusCode } ;
88use std:: collections:: HashMap ;
9- use std:: fs;
109use std:: io:: { self , Write } ;
1110use std:: net:: SocketAddr ;
1211use std:: ops:: Bound ;
1312use std:: path:: Path ;
1413use std:: sync:: { Arc , Mutex } ;
1514use std:: thread;
15+ use std:: { env, fs} ;
1616use tectonic:: config:: PersistentConfig ;
1717use tectonic:: driver:: ProcessingSessionBuilder ;
1818use tectonic:: io:: OpenResult ;
@@ -459,3 +459,48 @@ fn test_bundle_update() {
459459 }
460460 } ) ;
461461}
462+
463+ #[ test]
464+ fn test_cache_location_redirect ( ) {
465+ const CACHE_DIR_KEY : & str = "TECTONIC_CACHE_DIR" ;
466+ let tempdir = tempfile:: tempdir ( ) . unwrap ( ) ;
467+
468+ // In this test we intentionally set the environment variable and don't use the custom cache root parameter,
469+ // to test the internal mechanism for a custom cache location based on an environment variable.
470+ env:: set_var ( CACHE_DIR_KEY , tempdir. path ( ) . as_os_str ( ) ) ;
471+
472+ let tar_index = {
473+ let mut builder = TarIndexBuilder :: new ( ) ;
474+ builder. push ( "plain.tex" , b"simple" ) . push (
475+ tectonic:: digest:: DIGEST_NAME ,
476+ b"0000000000000000000000000000000000000000000000000000000000000000" ,
477+ ) ;
478+
479+ builder. finish ( )
480+ } ;
481+
482+ run_test ( Some ( tar_index) , |_, url| {
483+ let mut status = TermcolorStatusBackend :: new ( ChatterLevel :: Minimal ) ;
484+ let config = PersistentConfig :: default ( ) ;
485+
486+ let mut cache = config
487+ . make_cached_url_provider ( url, false , None , & mut status)
488+ . unwrap ( ) ;
489+
490+ match cache. input_open_name ( "plain.tex" , & mut status) {
491+ OpenResult :: Ok ( _) => { }
492+ _ => panic ! ( "Failed to open plain.tex" ) ,
493+ }
494+
495+ // the filename of the target location is the SHA256 hash of the file content "simple"
496+ let expected_file_path = tempdir
497+ . path ( )
498+ . join ( "files" )
499+ . join ( "a7" )
500+ . join ( "a39b72f29718e653e73503210fbb597057b7a1c77d1fe321a1afcff041d4e1" ) ;
501+
502+ if !expected_file_path. exists ( ) {
503+ panic ! ( "Couldn't find the cached file in the expected location." ) ;
504+ }
505+ } ) ;
506+ }
0 commit comments