fix osstring serialize/deserialize bugs

This commit is contained in:
(null)
2023-09-07 04:35:46 -04:00
parent f830ac9bfe
commit cc10ca249e
7 changed files with 7 additions and 13 deletions

View File

@@ -28,7 +28,6 @@ use self::aux::Set;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashMap;
use std::ffi::OsString;
pub const OCI_IMAGE_INDEX: &str = "application/vnd.oci.image.index.v1+json";
pub const OCI_MANIFEST: &str = "application/vnd.oci.image.manifest.v1+json";
@@ -181,7 +180,7 @@ pub struct OciInnerConfig {
pub env: Option<Vec<String>>,
pub tty: Option<bool>,
pub working_dir: Option<String>,
pub volumes: Option<Set<OsString>>,
pub volumes: Option<Set<String>>,
pub exposed_ports: Option<Set<String>>,
pub user: Option<String>,
pub labels: Option<HashMap<String, String>>,

View File

@@ -192,7 +192,7 @@ impl PatchActions {
destination: mount_point.to_path_buf(),
required: *required,
};
config.mounts.insert(key, mountspec);
config.mounts.insert(key.to_string_lossy().to_string(), mountspec);
}
PatchActions::ModAllow { allows } => {
for allow in allows.iter() {

View File

@@ -114,7 +114,7 @@ impl ConfigMod {
}
}
Self::Volume(name, mount_spec) => {
config.mounts.insert(name.clone(), mount_spec.clone());
config.mounts.insert(name.to_string_lossy().to_string(), mount_spec.clone());
}
Self::WorkDir(entry_point, dir) => {
let work_dir = dir.to_string();

View File

@@ -255,15 +255,12 @@ impl ImageStore for SqliteImageStore {
while let Ok(Some(row)) = rows.next() {
let bytes: String = row.get(4)?;
let manifest: JailImage = serde_json::from_str(&bytes)?;
let hn: String = row.get(0)?;
let image_reference = ImageReference {
hostname: if hn.is_empty() { None } else { Some(hn) },
name: row.get(1)?,
tag: ImageTag::Tag(row.get(2)?),
};
records.push(ImageRecord {
image_reference,
digest: row.get(3)?,

View File

@@ -36,7 +36,6 @@ use oci_util::layer::ChainId;
use oci_util::models::{FreeOciConfig, OciConfig, OciConfigRootFs, OciInnerConfig};
use serde::{de::Visitor, Deserialize, Deserializer, Serialize, Serializer};
use std::collections::HashMap;
use std::ffi::OsString;
use varutil::string_interpolation::{InterpolatedString, Var};
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
@@ -153,7 +152,6 @@ pub struct JailConfig {
/// The secure level this jail is required
pub secure_level: i8,
// pub original_oci_config: Option<OciConfig>,
/// is vnet required
#[serde(default)]
pub vnet: bool,
@@ -184,7 +182,7 @@ pub struct JailConfig {
pub special_mounts: Vec<SpecialMount>,
pub mounts: HashMap<OsString, MountSpec>,
pub mounts: HashMap<String, MountSpec>,
#[serde(default)]
pub datasets: HashMap<String, DatasetSpec>,

View File

@@ -201,7 +201,7 @@ impl AppliedInstantiateRequest {
}
}
mount_specs.remove(&req.dest);
mount_specs.remove(req.dest.to_str().unwrap());
}
for (key, spec) in mount_specs.iter() {
@@ -442,7 +442,7 @@ impl InstantiateBlueprint {
}
};
let mount_spec = mount_specs.remove(&req.dest);
let mount_spec = mount_specs.remove(req.dest.to_str().unwrap());
if mount_spec.is_some() {
added_mount_specs.insert(&req.dest, mount_spec.clone().unwrap());

View File

@@ -1170,7 +1170,7 @@ async fn create_volume(
{
Ok(image) => {
let specs = image.manifest.jail_config().mounts;
specs.get(&volume).cloned()
specs.get(volume.to_str().unwrap()).cloned()
}
Err(ImageStoreError::ManifestNotFound(manifest)) => {
return enoent(&format!("no such manifest {manifest}"))