@@ -174,8 +174,6 @@ fn prepare_sandbox_rootfs(rootfs: &Path) -> Result<(), String> {
174174 fs:: write ( opt_dir. join ( ".rootfs-type" ) , "sandbox\n " )
175175 . map_err ( |e| format ! ( "write sandbox rootfs marker: {e}" ) ) ?;
176176 ensure_sandbox_guest_user ( rootfs) ?;
177- fs:: create_dir_all ( rootfs. join ( "sandbox" ) )
178- . map_err ( |e| format ! ( "create sandbox workdir: {e}" ) ) ?;
179177
180178 Ok ( ( ) )
181179}
@@ -365,7 +363,7 @@ mod tests {
365363 assert ! ( !rootfs. join( "opt/openshell/charts" ) . exists( ) ) ;
366364 assert ! ( !rootfs. join( "opt/openshell/manifests" ) . exists( ) ) ;
367365 assert ! ( rootfs. join( "srv/openshell-vm-sandbox-init.sh" ) . is_file( ) ) ;
368- assert ! ( rootfs. join( "sandbox" ) . is_dir ( ) ) ;
366+ assert ! ( ! rootfs. join( "sandbox" ) . exists ( ) ) ;
369367 assert ! (
370368 fs:: read_to_string( rootfs. join( "etc/passwd" ) )
371369 . expect( "read passwd" )
@@ -384,6 +382,30 @@ mod tests {
384382 let _ = fs:: remove_dir_all ( & dir) ;
385383 }
386384
385+ #[ test]
386+ fn prepare_sandbox_rootfs_preserves_image_workdir_contents ( ) {
387+ let dir = unique_temp_dir ( ) ;
388+ let rootfs = dir. join ( "rootfs" ) ;
389+
390+ fs:: create_dir_all ( rootfs. join ( "opt/openshell/bin" ) ) . expect ( "create openshell bin" ) ;
391+ fs:: write (
392+ rootfs. join ( "opt/openshell/bin/openshell-sandbox" ) ,
393+ b"sandbox" ,
394+ )
395+ . expect ( "write openshell-sandbox" ) ;
396+ fs:: create_dir_all ( rootfs. join ( "sandbox" ) ) . expect ( "create sandbox workdir" ) ;
397+ fs:: write ( rootfs. join ( "sandbox/app.py" ) , "print('hello')\n " ) . expect ( "write app" ) ;
398+
399+ prepare_sandbox_rootfs ( & rootfs) . expect ( "prepare sandbox rootfs" ) ;
400+
401+ assert_eq ! (
402+ fs:: read_to_string( rootfs. join( "sandbox/app.py" ) ) . expect( "read app" ) ,
403+ "print('hello')\n "
404+ ) ;
405+
406+ let _ = fs:: remove_dir_all ( & dir) ;
407+ }
408+
387409 #[ cfg( unix) ]
388410 #[ test]
389411 fn create_rootfs_archive_preserves_broken_symlinks ( ) {
0 commit comments