Skip to content

Commit

Permalink
fix(sb_graph): failed to deserialize in the v1.1 migration phase due …
Browse files Browse the repository at this point in the history
…to specifying the wrong type (#403)
  • Loading branch information
nyannyacha authored Aug 29, 2024
1 parent 5d4a9b4 commit e41c1b6
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions crates/sb_graph/eszip_migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ mod v1_1 {
Arc::from(b"1.1" as &[u8]),
);

let mut v1_dir = {
let v1_dir = {
let Some(vfs_mod_data) = OptionFuture::<_>::from(
v1_eszip
.ensure_module(VFS_ESZIP_KEY)
Expand All @@ -307,23 +307,27 @@ mod v1_1 {
return Ok(v1_1_eszip);
};

let Ok(v1_dir) = rkyv::from_bytes::<v1::Directory>(&vfs_mod_data) else {
let Ok(v1_dir) = rkyv::from_bytes::<Option<v1::Directory>>(&vfs_mod_data) else {
bail!("cannot deserialize vfs data");
};

v1_dir
};

if v1_dir.name != "node_modules" {
bail!("malformed vfs data (expected node_modules)");
}
let v1_1_dir = if let Some(mut v1_dir) = v1_dir {
if v1_dir.name != "node_modules" {
bail!("malformed vfs data (expected node_modules)");
}

v1_dir.name = "localhost".into();
v1_dir.name = "localhost".into();

let v1_1_dir = Some(v1::Directory {
name: "node_modules".into(),
entries: vec![v1::Entry::Dir(v1_dir)],
});
Some(v1::Directory {
name: "node_modules".into(),
entries: vec![v1::Entry::Dir(v1_dir)],
})
} else {
None
};

let v1_1_vfs_data = rkyv::to_bytes::<_, 1024>(&v1_1_dir)
.with_context(|| "failed to serialize v1.1 vfs data")?;
Expand Down

0 comments on commit e41c1b6

Please sign in to comment.