mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +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};
|
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(
|
fn get_fd(
|
||||||
fds: &mut Vec<Option<crate::FileHandle>>,
|
fds: &mut Vec<Option<crate::FileHandle>>,
|
||||||
fd: usize,
|
fd: usize,
|
||||||
|
|
@ -74,7 +84,7 @@ pub(crate) fn stat_path(
|
||||||
for s in &basis_list {
|
for s in &basis_list {
|
||||||
if s == basis {
|
if s == basis {
|
||||||
// Kind
|
// Kind
|
||||||
writer.append(0u8);
|
writer.append(FileType::Basis as u8);
|
||||||
// Length
|
// Length
|
||||||
writer.append(0u64);
|
writer.append(0u64);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
|
@ -83,7 +93,7 @@ pub(crate) fn stat_path(
|
||||||
|
|
||||||
// Otherwise, indicate it's nothing
|
// Otherwise, indicate it's nothing
|
||||||
log::error!("remainder is empty on {} and basis doesn't exist", path);
|
log::error!("remainder is empty on {} and basis doesn't exist", path);
|
||||||
writer.append(4u8);
|
writer.append(FileType::None as u8);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -92,7 +102,7 @@ pub(crate) fn stat_path(
|
||||||
|
|
||||||
// The root is a dict
|
// The root is a dict
|
||||||
if stripped_path == "" {
|
if stripped_path == "" {
|
||||||
writer.append(1u8); // Dict
|
writer.append(FileType::Dict as u8); // Dict
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -120,15 +130,12 @@ pub(crate) fn stat_path(
|
||||||
|
|
||||||
// Add the count of entries
|
// Add the count of entries
|
||||||
let val = match (is_dict, is_key) {
|
let val = match (is_dict, is_key) {
|
||||||
(true, false) => 1u8,
|
(true, false) => FileType::Dict,
|
||||||
(false, true) => 2u8,
|
(false, true) => FileType::Key,
|
||||||
(true, true) => 3u8,
|
(true, true) => FileType::DictKey,
|
||||||
(false, false) => 4u8,
|
(false, false) => FileType::None,
|
||||||
};
|
};
|
||||||
if val == 4 {
|
writer.append(val as u8);
|
||||||
log::error!("path {} couldn't be found", path);
|
|
||||||
}
|
|
||||||
writer.append(val);
|
|
||||||
// Placeholder for file length
|
// Placeholder for file length
|
||||||
writer.append(0u64);
|
writer.append(0u64);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue