@@ -1132,7 +1132,16 @@ async fn test_container_var_content() -> Result<()> {
1132
1132
}
1133
1133
1134
1134
#[ tokio:: test]
1135
- async fn test_container_etc_hardlinked ( ) -> Result < ( ) > {
1135
+ async fn test_container_etc_hardlinked_absolute ( ) -> Result < ( ) > {
1136
+ test_container_etc_hardlinked ( true ) . await
1137
+ }
1138
+
1139
+ #[ tokio:: test]
1140
+ async fn test_container_etc_hardlinked_relative ( ) -> Result < ( ) > {
1141
+ test_container_etc_hardlinked ( false ) . await
1142
+ }
1143
+
1144
+ async fn test_container_etc_hardlinked ( absolute : bool ) -> Result < ( ) > {
1136
1145
let fixture = Fixture :: new_v1 ( ) ?;
1137
1146
1138
1147
let imgref = fixture. export_container ( ) . await . unwrap ( ) . 0 ;
@@ -1174,6 +1183,7 @@ async fn test_container_etc_hardlinked() -> Result<()> {
1174
1183
// Another case where we have /etc/dnf.conf and a hardlinked /ostree/repo/objects
1175
1184
// link into it - in this case we should ignore the hardlinked one.
1176
1185
let testdata = "hardlinked into object store" ;
1186
+ let mut h = tar:: Header :: new_ustar ( ) ;
1177
1187
h. set_mode ( 0o644 ) ;
1178
1188
h. set_mtime ( 42 ) ;
1179
1189
h. set_size ( testdata. len ( ) . try_into ( ) . unwrap ( ) ) ;
@@ -1186,7 +1196,20 @@ async fn test_container_etc_hardlinked() -> Result<()> {
1186
1196
h. set_entry_type ( tar:: EntryType :: Link ) ;
1187
1197
h. set_mtime ( 42 ) ;
1188
1198
h. set_size ( 0 ) ;
1189
- layer_tar. append_link ( & mut h. clone ( ) , "sysroot/ostree/repo/objects/45/7279b28b541ca20358bec8487c81baac6a3d5ed3cea019aee675137fab53cb.file" , "etc/dnf.conf" ) ?;
1199
+ let path = "sysroot/ostree/repo/objects/45/7279b28b541ca20358bec8487c81baac6a3d5ed3cea019aee675137fab53cb.file" ;
1200
+ let target = "etc/dnf.conf" ;
1201
+ if absolute {
1202
+ let ustarname = & mut h. as_ustar_mut ( ) . unwrap ( ) . name ;
1203
+ // The tar crate doesn't let us set absolute paths in tar archives, so we bypass
1204
+ // it and just write to the path buffer directly.
1205
+ assert ! ( path. len( ) < ustarname. len( ) ) ;
1206
+ ustarname[ 0 ..path. len ( ) ] . copy_from_slice ( path. as_bytes ( ) ) ;
1207
+ h. set_link_name ( target) ?;
1208
+ h. set_cksum ( ) ;
1209
+ layer_tar. append ( & mut h. clone ( ) , std:: io:: empty ( ) ) ?;
1210
+ } else {
1211
+ layer_tar. append_link ( & mut h. clone ( ) , path, target) ?;
1212
+ }
1190
1213
layer_tar. finish ( ) ?;
1191
1214
Ok ( ( ) )
1192
1215
} ,
@@ -1221,6 +1244,10 @@ async fn test_container_etc_hardlinked() -> Result<()> {
1221
1244
bar. ensure_resolved ( ) ?;
1222
1245
assert_eq ! ( foo. checksum( ) , bar. checksum( ) ) ;
1223
1246
1247
+ let dnfconf = r. resolve_relative_path ( "usr/etc/dnf.conf" ) ;
1248
+ let dnfconf: & ostree:: RepoFile = dnfconf. downcast_ref :: < ostree:: RepoFile > ( ) . unwrap ( ) ;
1249
+ dnfconf. ensure_resolved ( ) ?;
1250
+
1224
1251
Ok ( ( ) )
1225
1252
}
1226
1253
0 commit comments