fix(backend): backend doesn't store labels coming from filenames as hashes
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
Tomáš Mládek 2024-08-10 19:15:47 +02:00
parent 01b8815f46
commit 92d5e0190b

View file

@ -495,17 +495,35 @@ impl FsStore {
connection.insert_entry(mime_entry)?;
}
let label = {
if let Some(name) = name {
Some(name)
} else {
let hash = b58_encode(blob_address.encode()?);
let filename = filename.as_os_str().to_string_lossy().to_string();
if filename.starts_with(&hash) {
let rest = filename.split_at(hash.len()).1;
let rest = rest.trim_start_matches(|ch| !char::is_alphanumeric(ch));
(!rest.is_empty()).then_some(rest.to_string())
} else {
Some(filename)
}
}
};
let mut label_entry_addr = None;
if let Some(label) = label {
let label_entry = Entry {
entity: blob_address.clone(),
attribute: ATTR_LABEL.parse().unwrap(),
value: name
.unwrap_or_else(|| filename.as_os_str().to_string_lossy().to_string())
.into(),
value: label.into(),
provenance: "SYSTEM INIT".to_string(),
timestamp: chrono::Utc::now().naive_utc(),
user: context.user.clone(),
};
let label_entry_addr = connection.insert_entry(label_entry)?;
label_entry_addr = Some(connection.insert_entry(label_entry)?);
}
if let Some(upath) = upath {
let resolved_path = match resolve_cache {
@ -526,6 +544,7 @@ impl FsStore {
};
let dir_has_entry_addr = connection.insert_entry(dir_has_entry)?;
if let Some(label_entry_addr) = label_entry_addr {
let alias_entry = Entry {
entity: dir_has_entry_addr,
attribute: ATTR_BY.parse().unwrap(),
@ -536,6 +555,7 @@ impl FsStore {
};
connection.insert_entry(alias_entry)?;
}
}
Ok(blob_address)
}