Skip to content

Commit a2411ee

Browse files
committed
builder: prepend stargz root entry automatically
Signed-off-by: Yan Song <yansong.ys@antfin.com>
1 parent 73ac62a commit a2411ee

File tree

3 files changed

+10
-19
lines changed

3 files changed

+10
-19
lines changed

src/bin/nydus-image/builder/stargz.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ impl TocIndex {
298298
fn load(path: &Path) -> Result<TocIndex> {
299299
let index_file = File::open(path)
300300
.with_context(|| format!("failed to open stargz index file {:?}", path))?;
301-
let toc_index: TocIndex = serde_json::from_reader(index_file)
301+
let mut toc_index: TocIndex = serde_json::from_reader(index_file)
302302
.with_context(|| format!("invalid stargz index file {:?}", path))?;
303303

304304
if toc_index.version != 1 {
@@ -308,6 +308,15 @@ impl TocIndex {
308308
)));
309309
}
310310

311+
// Append root directory entry if not exists.
312+
if !toc_index.entries.is_empty() && toc_index.entries[0].name()? != PathBuf::from("/") {
313+
let root_entry = TocEntry {
314+
toc_type: String::from("dir"),
315+
..Default::default()
316+
};
317+
toc_index.entries.insert(0, root_entry);
318+
}
319+
311320
Ok(toc_index)
312321
}
313322
}

tests/texture/stargz/stargz.index-lower.json

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
{
22
"version": 1,
33
"entries": [
4-
{
5-
"name": "",
6-
"type": "dir",
7-
"modtime": "2020-09-10T07:40:29Z",
8-
"mode": 493,
9-
"userName": "root",
10-
"groupName": "root",
11-
"NumLink": 0
12-
},
134
{
145
"name": "root-large",
156
"type": "reg",

tests/texture/stargz/stargz.index-upper.json

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
{
22
"version": 1,
33
"entries": [
4-
{
5-
"name": "",
6-
"type": "dir",
7-
"modtime": "2020-09-10T06:43:07Z",
8-
"mode": 493,
9-
"userName": "root",
10-
"groupName": "root",
11-
"NumLink": 0
12-
},
134
{
145
"name": "sub/",
156
"type": "dir",

0 commit comments

Comments
 (0)