feat: make digest_value optional and add digest display
This commit is contained in:
committed by
Andrew Phillips (aider)
parent
1d9ca1b9dd
commit
1aaf1e6221
@@ -32,9 +32,6 @@ lazy_static! {
|
|||||||
FOREIGN KEY(id) REFERENCES items(id) ON DELETE CASCADE,
|
FOREIGN KEY(id) REFERENCES items(id) ON DELETE CASCADE,
|
||||||
PRIMARY KEY(id, name));"
|
PRIMARY KEY(id, name));"
|
||||||
),
|
),
|
||||||
M::up(
|
|
||||||
"ALTER TABLE items ALTER COLUMN compression SET DEFAULT 'none';"
|
|
||||||
),
|
|
||||||
M::up(
|
M::up(
|
||||||
"ALTER TABLE items ADD COLUMN digest_type TEXT NOT NULL DEFAULT 'none';"
|
"ALTER TABLE items ADD COLUMN digest_type TEXT NOT NULL DEFAULT 'none';"
|
||||||
),
|
),
|
||||||
@@ -51,7 +48,7 @@ pub struct Item {
|
|||||||
pub size: Option<i64>,
|
pub size: Option<i64>,
|
||||||
pub compression: String,
|
pub compression: String,
|
||||||
pub digest_type: String,
|
pub digest_type: String,
|
||||||
pub digest_value: String,
|
pub digest_value: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ pub enum ColumnType {
|
|||||||
Time,
|
Time,
|
||||||
Size,
|
Size,
|
||||||
Compression,
|
Compression,
|
||||||
|
DigestType,
|
||||||
|
DigestValue,
|
||||||
FileSize,
|
FileSize,
|
||||||
FilePath,
|
FilePath,
|
||||||
Tags,
|
Tags,
|
||||||
|
|||||||
@@ -142,6 +142,17 @@ pub fn mode_list(
|
|||||||
ColumnType::Compression => {
|
ColumnType::Compression => {
|
||||||
Cell::new(&string_column(item.compression.to_string(), column_width))
|
Cell::new(&string_column(item.compression.to_string(), column_width))
|
||||||
}
|
}
|
||||||
|
ColumnType::DigestType => {
|
||||||
|
Cell::new(&string_column(item.digest_type.to_string(), column_width))
|
||||||
|
}
|
||||||
|
ColumnType::DigestValue => {
|
||||||
|
match item.digest_value {
|
||||||
|
Some(ref value) => Cell::new(&string_column(value.to_string(), column_width)),
|
||||||
|
None => Cell::new("Missing")
|
||||||
|
.with_style(Attr::ForegroundColor(color::RED))
|
||||||
|
.with_style(Attr::Bold),
|
||||||
|
}
|
||||||
|
}
|
||||||
ColumnType::FileSize => match item_path.metadata() {
|
ColumnType::FileSize => match item_path.metadata() {
|
||||||
Ok(metadata) => Cell::new_align(
|
Ok(metadata) => Cell::new_align(
|
||||||
&size_column(
|
&size_column(
|
||||||
@@ -152,8 +163,8 @@ pub fn mode_list(
|
|||||||
Alignment::RIGHT,
|
Alignment::RIGHT,
|
||||||
),
|
),
|
||||||
Err(_) => Cell::new_align("Missing", Alignment::RIGHT)
|
Err(_) => Cell::new_align("Missing", Alignment::RIGHT)
|
||||||
.with_style(Attr::ForegroundColor(color::RED))
|
.with_style(Attr::ForegroundColor(color::RED))
|
||||||
.with_style(Attr::Bold),
|
.with_style(Attr::Bold),
|
||||||
},
|
},
|
||||||
ColumnType::FilePath => Cell::new(&string_column(
|
ColumnType::FilePath => Cell::new(&string_column(
|
||||||
item_path.clone().into_os_string().into_string().unwrap(),
|
item_path.clone().into_os_string().into_string().unwrap(),
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ pub fn mode_save(
|
|||||||
size: None,
|
size: None,
|
||||||
compression: compression_type.to_string(),
|
compression: compression_type.to_string(),
|
||||||
digest_type: digest_type.to_string(),
|
digest_type: digest_type.to_string(),
|
||||||
digest_value: String::new(),
|
digest_value: Some(String::new()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let id = db::insert_item(conn, item.clone())?;
|
let id = db::insert_item(conn, item.clone())?;
|
||||||
@@ -169,7 +169,7 @@ pub fn mode_save(
|
|||||||
// Finalize the digest and log the result
|
// Finalize the digest and log the result
|
||||||
let digest = digest_engine.finalize()?;
|
let digest = digest_engine.finalize()?;
|
||||||
debug!("DIGEST: {}", digest);
|
debug!("DIGEST: {}", digest);
|
||||||
item.digest_value = digest;
|
item.digest_value = Some(digest);
|
||||||
|
|
||||||
db::update_item(conn, item.clone())?;
|
db::update_item(conn, item.clone())?;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user