fix(backend): backend doesn't store labels coming from filenames as hashes
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
This commit is contained in:
parent
01b8815f46
commit
92d5e0190b
1 changed files with 39 additions and 19 deletions
|
@ -495,17 +495,35 @@ impl FsStore {
|
|||
connection.insert_entry(mime_entry)?;
|
||||
}
|
||||
|
||||
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(),
|
||||
provenance: "SYSTEM INIT".to_string(),
|
||||
timestamp: chrono::Utc::now().naive_utc(),
|
||||
user: context.user.clone(),
|
||||
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 label_entry_addr = connection.insert_entry(label_entry)?;
|
||||
|
||||
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: label.into(),
|
||||
provenance: "SYSTEM INIT".to_string(),
|
||||
timestamp: chrono::Utc::now().naive_utc(),
|
||||
user: context.user.clone(),
|
||||
};
|
||||
label_entry_addr = Some(connection.insert_entry(label_entry)?);
|
||||
}
|
||||
|
||||
if let Some(upath) = upath {
|
||||
let resolved_path = match resolve_cache {
|
||||
|
@ -526,15 +544,17 @@ impl FsStore {
|
|||
};
|
||||
let dir_has_entry_addr = connection.insert_entry(dir_has_entry)?;
|
||||
|
||||
let alias_entry = Entry {
|
||||
entity: dir_has_entry_addr,
|
||||
attribute: ATTR_BY.parse().unwrap(),
|
||||
value: label_entry_addr.into(),
|
||||
provenance: "SYSTEM INIT".to_string(),
|
||||
timestamp: chrono::Utc::now().naive_utc(),
|
||||
user: context.user.clone(),
|
||||
};
|
||||
connection.insert_entry(alias_entry)?;
|
||||
if let Some(label_entry_addr) = label_entry_addr {
|
||||
let alias_entry = Entry {
|
||||
entity: dir_has_entry_addr,
|
||||
attribute: ATTR_BY.parse().unwrap(),
|
||||
value: label_entry_addr.into(),
|
||||
provenance: "SYSTEM INIT".to_string(),
|
||||
timestamp: chrono::Utc::now().naive_utc(),
|
||||
user: context.user.clone(),
|
||||
};
|
||||
connection.insert_entry(alias_entry)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(blob_address)
|
||||
|
|
Loading…
Reference in a new issue