Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 45b0438c authored by Marybeth Fair's avatar Marybeth Fair
Browse files

Add ability to manually write to binary files.

I was updating the format of PackageTableHeader to add an additional
field (and due to that change incremented the file version). This broke
several tests under aconfig_storage_read_api and
aconfig_storage_write_api that were operating on files written in the
old schema. I tried to re-generate them using aconfig create-storage as
explained in aosp/2933375, but was having some trouble. Figure if we can
just update the files directly it will be easier to make updates in the
future anyway. This isn't bypassing logic that's tested - IIUC the tests
cover reading the file correctly (writing is covered in separate tests).

Usage:
$ aconfig-storage print --file=path/to/flag.map --type=flag_map
--format=json > flag_map.json
$ vim flag_map.json // Manually make updates
$ aconfig-storage write-bytes --input-file=flag_map.json
--output-file=path/to/flag.map --type=flag_map

Change-Id: I212bf0b97483740b30130eb121acb895d350da84
Test: manual (adding debug-only tooling) + cargo t
Bug: 316357686
parent 1c0e2553
Loading
Loading
Loading
Loading
+5 −1
Original line number Original line Diff line number Diff line
@@ -14,6 +14,7 @@ rust_defaults {
        "libclap",
        "libclap",
        "libcxx",
        "libcxx",
        "libaconfig_storage_protos",
        "libaconfig_storage_protos",
        "libserde",
    ],
    ],
}
}


@@ -36,7 +37,10 @@ rust_binary_host {
    name: "aconfig-storage",
    name: "aconfig-storage",
    defaults: ["aconfig_storage_file.defaults"],
    defaults: ["aconfig_storage_file.defaults"],
    srcs: ["src/main.rs"],
    srcs: ["src/main.rs"],
    rustlibs: ["libaconfig_storage_file"],
    rustlibs: [
        "libaconfig_storage_file",
        "libserde_json",
    ],
}
}


rust_test_host {
rust_test_host {
+2 −0
Original line number Original line Diff line number Diff line
@@ -14,6 +14,8 @@ tempfile = "3.9.0"
thiserror = "1.0.56"
thiserror = "1.0.56"
clap = { version = "4.1.8", features = ["derive"] }
clap = { version = "4.1.8", features = ["derive"] }
cxx = "1.0"
cxx = "1.0"
serde = { version = "1.0.152", features = ["derive"] }
serde_json = "1.0.93"


[[bin]]
[[bin]]
name = "aconfig-storage"
name = "aconfig-storage"
+5 −4
Original line number Original line Diff line number Diff line
@@ -20,10 +20,11 @@
use crate::{read_str_from_bytes, read_u32_from_bytes, read_u8_from_bytes};
use crate::{read_str_from_bytes, read_u32_from_bytes, read_u8_from_bytes};
use crate::{AconfigStorageError, StorageFileType};
use crate::{AconfigStorageError, StorageFileType};
use anyhow::anyhow;
use anyhow::anyhow;
use serde::{Deserialize, Serialize};
use std::fmt;
use std::fmt;


/// Flag info header struct
/// Flag info header struct
#[derive(PartialEq)]
#[derive(PartialEq, Serialize, Deserialize)]
pub struct FlagInfoHeader {
pub struct FlagInfoHeader {
    pub version: u32,
    pub version: u32,
    pub container: String,
    pub container: String,
@@ -89,7 +90,7 @@ impl FlagInfoHeader {
}
}


/// bit field for flag info
/// bit field for flag info
#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum FlagInfoBit {
pub enum FlagInfoBit {
    HasServerOverride = 1 << 0,
    HasServerOverride = 1 << 0,
    IsReadWrite = 1 << 1,
    IsReadWrite = 1 << 1,
@@ -97,7 +98,7 @@ pub enum FlagInfoBit {
}
}


/// Flag info node struct
/// Flag info node struct
#[derive(PartialEq, Clone)]
#[derive(PartialEq, Clone, Serialize, Deserialize)]
pub struct FlagInfoNode {
pub struct FlagInfoNode {
    pub attributes: u8,
    pub attributes: u8,
}
}
@@ -138,7 +139,7 @@ impl FlagInfoNode {
}
}


/// Flag info list struct
/// Flag info list struct
#[derive(PartialEq)]
#[derive(PartialEq, Serialize, Deserialize)]
pub struct FlagInfoList {
pub struct FlagInfoList {
    pub header: FlagInfoHeader,
    pub header: FlagInfoHeader,
    pub nodes: Vec<FlagInfoNode>,
    pub nodes: Vec<FlagInfoNode>,
+4 −3
Original line number Original line Diff line number Diff line
@@ -23,10 +23,11 @@ use crate::{
};
};
use crate::{AconfigStorageError, StorageFileType, StoredFlagType};
use crate::{AconfigStorageError, StorageFileType, StoredFlagType};
use anyhow::anyhow;
use anyhow::anyhow;
use serde::{Deserialize, Serialize};
use std::fmt;
use std::fmt;


/// Flag table header struct
/// Flag table header struct
#[derive(PartialEq)]
#[derive(PartialEq, Serialize, Deserialize)]
pub struct FlagTableHeader {
pub struct FlagTableHeader {
    pub version: u32,
    pub version: u32,
    pub container: String,
    pub container: String,
@@ -95,7 +96,7 @@ impl FlagTableHeader {
}
}


/// Flag table node struct
/// Flag table node struct
#[derive(PartialEq, Clone)]
#[derive(PartialEq, Clone, Serialize, Deserialize)]
pub struct FlagTableNode {
pub struct FlagTableNode {
    pub package_id: u32,
    pub package_id: u32,
    pub flag_name: String,
    pub flag_name: String,
@@ -154,7 +155,7 @@ impl FlagTableNode {
    }
    }
}
}


#[derive(PartialEq)]
#[derive(PartialEq, Serialize, Deserialize)]
pub struct FlagTable {
pub struct FlagTable {
    pub header: FlagTableHeader,
    pub header: FlagTableHeader,
    pub buckets: Vec<Option<u32>>,
    pub buckets: Vec<Option<u32>>,
+3 −2
Original line number Original line Diff line number Diff line
@@ -20,10 +20,11 @@
use crate::{read_str_from_bytes, read_u32_from_bytes, read_u8_from_bytes};
use crate::{read_str_from_bytes, read_u32_from_bytes, read_u8_from_bytes};
use crate::{AconfigStorageError, StorageFileType};
use crate::{AconfigStorageError, StorageFileType};
use anyhow::anyhow;
use anyhow::anyhow;
use serde::{Deserialize, Serialize};
use std::fmt;
use std::fmt;


/// Flag value header struct
/// Flag value header struct
#[derive(PartialEq)]
#[derive(PartialEq, Serialize, Deserialize)]
pub struct FlagValueHeader {
pub struct FlagValueHeader {
    pub version: u32,
    pub version: u32,
    pub container: String,
    pub container: String,
@@ -89,7 +90,7 @@ impl FlagValueHeader {
}
}


/// Flag value list struct
/// Flag value list struct
#[derive(PartialEq)]
#[derive(PartialEq, Serialize, Deserialize)]
pub struct FlagValueList {
pub struct FlagValueList {
    pub header: FlagValueHeader,
    pub header: FlagValueHeader,
    pub booleans: Vec<bool>,
    pub booleans: Vec<bool>,
Loading