If a size is mssing for an item, --update will set it

This commit is contained in:
Andrew Phillips
2023-09-20 19:04:01 +00:00
parent d189f27db8
commit f425e0df66

View File

@@ -299,7 +299,7 @@ fn main() -> Result<(), Error> {
KeepModes::Save => mode_save(&mut cmd, args, ids, tags, conn, data_path)?,
KeepModes::Get => mode_get(&mut cmd, args, ids, tags, &mut conn, data_path)?,
KeepModes::List => mode_list(&mut cmd, args, ids, tags, &mut conn, data_path)?,
KeepModes::Update => mode_update(&mut cmd, args, ids, tags, &mut conn)?,
KeepModes::Update => mode_update(&mut cmd, args, ids, tags, &mut conn, data_path)?,
KeepModes::Info => mode_info(&mut cmd, args, ids, tags, &mut conn, data_path)?,
KeepModes::Delete => mode_delete(&mut cmd, args, ids, tags, &mut conn, data_path)?,
KeepModes::Status => mode_status(&mut cmd, args, data_path, db_path)?,
@@ -596,7 +596,7 @@ fn mode_list(cmd: &mut Command, args: Args, ids: &mut Vec<i64>, tags: &Vec<Strin
}
fn mode_update(cmd: &mut Command, args: Args, ids: &mut Vec<i64>, tags: &mut Vec<String>, conn: &mut Connection) -> Result<()> {
fn mode_update(cmd: &mut Command, args: Args, ids: &mut Vec<i64>, tags: &mut Vec<String>, conn: &mut Connection, data_path: PathBuf) -> Result<()> {
if ids.is_empty() {
cmd.error(ErrorKind::InvalidValue, "No ID given, you must supply exactly one ID when using --update").exit();
} else if ids.len() > 1 {
@@ -606,7 +606,7 @@ fn mode_update(cmd: &mut Command, args: Args, ids: &mut Vec<i64>, tags: &mut Vec
let item_id = ids.iter().next().expect("Unable to determine item id");
let item_maybe = db::get_item(conn, *item_id)?;
let item = item_maybe.expect("Unable to find item in database");
let mut item = item_maybe.expect("Unable to find item in database");
debug!("MAIN: Found item {:?}", item);
if ! tags.is_empty() {
@@ -614,6 +614,24 @@ fn mode_update(cmd: &mut Command, args: Args, ids: &mut Vec<i64>, tags: &mut Vec
db::set_item_tags(conn, item.clone(), tags)?;
}
if item.size.is_none() {
info!("Updating unknown stream size");
let mut item_path = data_path.clone();
item_path.push(item.id.unwrap().to_string());
let item_file_metadata = item_path.metadata();
if item_file_metadata.is_ok() {
debug!("MAIN: Updating stream size of {:?}", item_path);
let compression_type = CompressionType::from_str(&item.compression)?;
let compression_engine = compression::get_engine(compression_type).expect("Unable to get compression engine");
let size = compression_engine.size(item_path)? as i64;
item.size = Some(size);
db::update_item(&conn, item.clone())?;
} else {
debug!("MAIN: Unable to update size of item due to missing file {:?}", item_path);
}
}
if args.item.meta.len() > 0 {
debug!("MAIN: Updating item meta");
for kv in args.item.meta.iter() {