@@ -24,9 +24,15 @@ const TUFTOOL: &[u8] = include_bytes!(env!("CARGO_BIN_FILE_TUFTOOL"));
2424pub ( crate ) async fn install_tools ( tools_dir : impl AsRef < Path > ) -> Result < ( ) > {
2525 let dir = tools_dir. as_ref ( ) ;
2626 debug ! ( "Installing tools to '{}'" , dir. display( ) ) ;
27+ fs:: remove_dir_all ( dir)
28+ . await
29+ . context ( "Unable to remove tools directory before installing" ) ?;
30+ fs:: create_dir_all ( dir)
31+ . await
32+ . context ( "Unable to create directory for tools" ) ?;
2733
2834 // Write out the embedded tools and scripts.
29- unpack_tarball ( & dir)
35+ unpack_tarball ( dir)
3036 . await
3137 . context ( "Unable to install tools" ) ?;
3238
@@ -93,32 +99,31 @@ async fn unpack_tarball(tools_dir: impl AsRef<Path>) -> Result<()> {
9399#[ tokio:: test]
94100async fn test_install_tools ( ) {
95101 let tempdir = tempfile:: TempDir :: new ( ) . unwrap ( ) ;
96- install_tools ( & tempdir) . await . unwrap ( ) ;
102+ let toolsdir = tempdir. path ( ) . join ( "tools" ) ;
103+ install_tools ( & toolsdir) . await . unwrap ( ) ;
97104
98105 // Assert that the expected files exist in the tools directory.
99106
100107 // Check that non-binary files were copied.
101- assert ! ( tempdir . path ( ) . join( "Dockerfile" ) . is_file( ) ) ;
102- assert ! ( tempdir . path ( ) . join( "Makefile.toml" ) . is_file( ) ) ;
103- assert ! ( tempdir . path ( ) . join( "docker-go" ) . is_file( ) ) ;
104- assert ! ( tempdir . path ( ) . join( "partyplanner" ) . is_file( ) ) ;
105- assert ! ( tempdir . path ( ) . join( "rpm2img" ) . is_file( ) ) ;
106- assert ! ( tempdir . path ( ) . join( "rpm2kmodkit" ) . is_file( ) ) ;
107- assert ! ( tempdir . path ( ) . join( "rpm2migrations" ) . is_file( ) ) ;
108+ assert ! ( toolsdir . join( "Dockerfile" ) . is_file( ) ) ;
109+ assert ! ( toolsdir . join( "Makefile.toml" ) . is_file( ) ) ;
110+ assert ! ( toolsdir . join( "docker-go" ) . is_file( ) ) ;
111+ assert ! ( toolsdir . join( "partyplanner" ) . is_file( ) ) ;
112+ assert ! ( toolsdir . join( "rpm2img" ) . is_file( ) ) ;
113+ assert ! ( toolsdir . join( "rpm2kmodkit" ) . is_file( ) ) ;
114+ assert ! ( toolsdir . join( "rpm2migrations" ) . is_file( ) ) ;
108115
109116 // Check that binaries were copied.
110- assert ! ( tempdir . path ( ) . join( "bottlerocket-variant" ) . is_file( ) ) ;
111- assert ! ( tempdir . path ( ) . join( "buildsys" ) . is_file( ) ) ;
112- assert ! ( tempdir . path ( ) . join( "pubsys" ) . is_file( ) ) ;
113- assert ! ( tempdir . path ( ) . join( "pubsys-setup" ) . is_file( ) ) ;
114- assert ! ( tempdir . path ( ) . join( "testsys" ) . is_file( ) ) ;
115- assert ! ( tempdir . path ( ) . join( "tuftool" ) . is_file( ) ) ;
117+ assert ! ( toolsdir . join( "bottlerocket-variant" ) . is_file( ) ) ;
118+ assert ! ( toolsdir . join( "buildsys" ) . is_file( ) ) ;
119+ assert ! ( toolsdir . join( "pubsys" ) . is_file( ) ) ;
120+ assert ! ( toolsdir . join( "pubsys-setup" ) . is_file( ) ) ;
121+ assert ! ( toolsdir . join( "testsys" ) . is_file( ) ) ;
122+ assert ! ( toolsdir . join( "tuftool" ) . is_file( ) ) ;
116123
117124 // Check that the mtimes match.
118- let dockerfile_metadata = fs:: metadata ( tempdir. path ( ) . join ( "Dockerfile" ) )
119- . await
120- . unwrap ( ) ;
121- let buildsys_metadata = fs:: metadata ( tempdir. path ( ) . join ( "buildsys" ) ) . await . unwrap ( ) ;
125+ let dockerfile_metadata = fs:: metadata ( toolsdir. join ( "Dockerfile" ) ) . await . unwrap ( ) ;
126+ let buildsys_metadata = fs:: metadata ( toolsdir. join ( "buildsys" ) ) . await . unwrap ( ) ;
122127 let dockerfile_mtime = FileTime :: from_last_modification_time ( & dockerfile_metadata) ;
123128 let buildsys_mtime = FileTime :: from_last_modification_time ( & buildsys_metadata) ;
124129
0 commit comments