mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
services: pddb: use an enum for file types
Rather than hardcoding numbers, use an enum with the constant values. This will make it easier to reason about what the constants mean. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
d65f16b533
commit
dc4ca79834
1 changed files with 18 additions and 11 deletions
|
|
@ -7,6 +7,16 @@ use crate::FileHandle;
|
|||
|
||||
use senres::{Senres, SenresMut};
|
||||
|
||||
#[repr(u8)]
|
||||
enum FileType {
|
||||
Basis = 0,
|
||||
Dict = 1,
|
||||
Key = 2,
|
||||
DictKey = 3,
|
||||
None = 4,
|
||||
// Unknown = 5, // Currently unused
|
||||
}
|
||||
|
||||
fn get_fd(
|
||||
fds: &mut Vec<Option<crate::FileHandle>>,
|
||||
fd: usize,
|
||||
|
|
@ -74,7 +84,7 @@ pub(crate) fn stat_path(
|
|||
for s in &basis_list {
|
||||
if s == basis {
|
||||
// Kind
|
||||
writer.append(0u8);
|
||||
writer.append(FileType::Basis as u8);
|
||||
// Length
|
||||
writer.append(0u64);
|
||||
return Ok(());
|
||||
|
|
@ -83,7 +93,7 @@ pub(crate) fn stat_path(
|
|||
|
||||
// Otherwise, indicate it's nothing
|
||||
log::error!("remainder is empty on {} and basis doesn't exist", path);
|
||||
writer.append(4u8);
|
||||
writer.append(FileType::None as u8);
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
|
@ -92,7 +102,7 @@ pub(crate) fn stat_path(
|
|||
|
||||
// The root is a dict
|
||||
if stripped_path == "" {
|
||||
writer.append(1u8); // Dict
|
||||
writer.append(FileType::Dict as u8); // Dict
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
|
@ -120,15 +130,12 @@ pub(crate) fn stat_path(
|
|||
|
||||
// Add the count of entries
|
||||
let val = match (is_dict, is_key) {
|
||||
(true, false) => 1u8,
|
||||
(false, true) => 2u8,
|
||||
(true, true) => 3u8,
|
||||
(false, false) => 4u8,
|
||||
(true, false) => FileType::Dict,
|
||||
(false, true) => FileType::Key,
|
||||
(true, true) => FileType::DictKey,
|
||||
(false, false) => FileType::None,
|
||||
};
|
||||
if val == 4 {
|
||||
log::error!("path {} couldn't be found", path);
|
||||
}
|
||||
writer.append(val);
|
||||
writer.append(val as u8);
|
||||
// Placeholder for file length
|
||||
writer.append(0u64);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue