mirror of
https://github.com/m-labs/artiq.git
synced 2024-12-25 03:08:27 +08:00
config: error instead of empty value if key not found
This commit is contained in:
parent
8599be5550
commit
4bdb4c8e11
@ -9,6 +9,7 @@ pub enum Error {
|
||||
MissingSeparator { offset: usize },
|
||||
Utf8Error(str::Utf8Error),
|
||||
NoFlash,
|
||||
KeyNotFound
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
@ -28,6 +29,8 @@ impl fmt::Display for Error {
|
||||
write!(f, "{}", err),
|
||||
&Error::NoFlash =>
|
||||
write!(f, "flash memory is not present"),
|
||||
&Error::KeyNotFound =>
|
||||
write!(f, "key not found")
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -156,14 +159,16 @@ mod imp {
|
||||
f(Lock::take().and_then(|lock| {
|
||||
let mut iter = Iter::new(lock.data());
|
||||
let mut value = &[][..];
|
||||
let mut found = false;
|
||||
while let Some(result) = iter.next() {
|
||||
let (record_key, record_value) = result?;
|
||||
if key.as_bytes() == record_key {
|
||||
found = true;
|
||||
// last write wins
|
||||
value = record_value
|
||||
}
|
||||
}
|
||||
Ok(value)
|
||||
if found { Ok(value) } else { Err(Error::KeyNotFound) }
|
||||
}))
|
||||
}
|
||||
|
||||
|
@ -529,7 +529,7 @@ fn flash_kernel_worker(io: &Io, aux_mutex: &Mutex,
|
||||
|
||||
config::read(config_key, |result| {
|
||||
match result {
|
||||
Ok(kernel) if kernel.len() > 0 => unsafe {
|
||||
Ok(kernel) => unsafe {
|
||||
// kernel CPU cannot access the SPI flash address space directly,
|
||||
// so make a copy.
|
||||
kern_load(io, &mut session, Vec::from(kernel).as_ref())
|
||||
|
Loading…
Reference in New Issue
Block a user