File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -547,3 +547,36 @@ fn exclude_from_time_machine(path: &Path) {
547
547
// Errors are ignored, since it's an optional feature and failure
548
548
// doesn't prevent Cargo from working
549
549
}
550
+
551
+ /// Absolute path to an on-disk temporary directory.
552
+ /// It may be system-wide or user-specific depending on system conventions.
553
+ /// Used in layout.rs, only needed on Unix systems.
554
+ #[ cfg( unix) ]
555
+ pub fn persistent_temp_path ( ) -> Option < PathBuf > {
556
+ #[ cfg( target_os = "macos" ) ]
557
+ {
558
+ // "Library/Caches" should be obtained via NSFileManager's
559
+ // URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask
560
+ // However, cocoa-foundation doesn't have bindings for it yet.
561
+ // This path has remained stable for two decades,
562
+ // so hardcode it for simplicity (dirs crate does the same).
563
+ Some ( home:: home_dir ( ) ?. join ( "Library/Caches/Cargo" ) )
564
+ }
565
+ #[ cfg( not( target_os = "macos" ) ) ]
566
+ {
567
+ // XDG standard
568
+ if let Some ( path) = env:: var_os ( "XDG_CACHE_HOME" ) {
569
+ let path = PathBuf :: from ( path) ;
570
+ if path. is_absolute ( ) {
571
+ return Some ( path. join ( "cargo" ) ) ;
572
+ }
573
+ }
574
+ // FHS standard
575
+ // This is not using /tmp, because /tmp could be using ramfs.
576
+ let path = Path :: new ( "/var/tmp" ) ;
577
+ if path. exists ( ) {
578
+ return Some ( path. join ( "cargo" ) ) ;
579
+ }
580
+ None
581
+ }
582
+ }
You can’t perform that action at this time.
0 commit comments