@@ -675,6 +675,12 @@ fn require_systemd_pid1() -> Result<()> {
675
675
Ok ( ( ) )
676
676
}
677
677
678
+ // Ensure the `/var` directory exists.
679
+ fn ensure_var ( ) -> Result < ( ) > {
680
+ std:: fs:: create_dir_all ( "/var" ) ?;
681
+ Ok ( ( ) )
682
+ }
683
+
678
684
/// We want to have proper /tmp and /var/tmp without requiring the caller to set them up
679
685
/// in advance by manually specifying them via `podman run -v /tmp:/tmp` etc.
680
686
/// Unfortunately, it's quite complex right now to "gracefully" dynamically reconfigure
@@ -693,19 +699,24 @@ pub(crate) fn propagate_tmp_mounts_to_host() -> Result<()> {
693
699
if path. is_symlink ( ) {
694
700
continue ;
695
701
}
696
- std:: os:: unix:: fs:: symlink ( & target, & tmp)
697
- . with_context ( || format ! ( "Symlinking {target} to {tmp}" ) ) ?;
698
- let cwd = rustix:: fs:: cwd ( ) ;
699
- rustix:: fs:: renameat_with (
700
- cwd,
701
- path. as_os_str ( ) ,
702
- cwd,
703
- & tmp,
704
- rustix:: fs:: RenameFlags :: EXCHANGE ,
705
- )
706
- . with_context ( || format ! ( "Exchanging {path} <=> {tmp}" ) ) ?;
707
- std:: fs:: rename ( & tmp, format ! ( "{path}.old" ) )
708
- . with_context ( || format ! ( "Renaming old {tmp}" ) ) ?;
702
+ if path. try_exists ( ) ? {
703
+ std:: os:: unix:: fs:: symlink ( & target, & tmp)
704
+ . with_context ( || format ! ( "Symlinking {target} to {tmp}" ) ) ?;
705
+ let cwd = rustix:: fs:: cwd ( ) ;
706
+ rustix:: fs:: renameat_with (
707
+ cwd,
708
+ path. as_os_str ( ) ,
709
+ cwd,
710
+ & tmp,
711
+ rustix:: fs:: RenameFlags :: EXCHANGE ,
712
+ )
713
+ . with_context ( || format ! ( "Exchanging {path} <=> {tmp}" ) ) ?;
714
+ std:: fs:: rename ( & tmp, format ! ( "{path}.old" ) )
715
+ . with_context ( || format ! ( "Renaming old {tmp}" ) ) ?;
716
+ } else {
717
+ std:: os:: unix:: fs:: symlink ( & target, path)
718
+ . with_context ( || format ! ( "Symlinking {target} to {path}" ) ) ?;
719
+ } ;
709
720
}
710
721
Ok ( ( ) )
711
722
}
@@ -723,6 +734,7 @@ async fn prepare_install(
723
734
let container_info = crate :: containerenv:: get_container_execution_info ( ) ?;
724
735
let source = SourceInfo :: from_container ( & container_info) ?;
725
736
737
+ ensure_var ( ) ?;
726
738
propagate_tmp_mounts_to_host ( ) ?;
727
739
728
740
// Even though we require running in a container, the mounts we create should be specific
0 commit comments