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)?;
|
connection.insert_entry(mime_entry)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let label_entry = Entry {
|
let label = {
|
||||||
entity: blob_address.clone(),
|
if let Some(name) = name {
|
||||||
attribute: ATTR_LABEL.parse().unwrap(),
|
Some(name)
|
||||||
value: name
|
} else {
|
||||||
.unwrap_or_else(|| filename.as_os_str().to_string_lossy().to_string())
|
let hash = b58_encode(blob_address.encode()?);
|
||||||
.into(),
|
let filename = filename.as_os_str().to_string_lossy().to_string();
|
||||||
provenance: "SYSTEM INIT".to_string(),
|
if filename.starts_with(&hash) {
|
||||||
timestamp: chrono::Utc::now().naive_utc(),
|
let rest = filename.split_at(hash.len()).1;
|
||||||
user: context.user.clone(),
|
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 {
|
if let Some(upath) = upath {
|
||||||
let resolved_path = match resolve_cache {
|
let resolved_path = match resolve_cache {
|
||||||
|
@ -526,15 +544,17 @@ impl FsStore {
|
||||||
};
|
};
|
||||||
let dir_has_entry_addr = connection.insert_entry(dir_has_entry)?;
|
let dir_has_entry_addr = connection.insert_entry(dir_has_entry)?;
|
||||||
|
|
||||||
let alias_entry = Entry {
|
if let Some(label_entry_addr) = label_entry_addr {
|
||||||
entity: dir_has_entry_addr,
|
let alias_entry = Entry {
|
||||||
attribute: ATTR_BY.parse().unwrap(),
|
entity: dir_has_entry_addr,
|
||||||
value: label_entry_addr.into(),
|
attribute: ATTR_BY.parse().unwrap(),
|
||||||
provenance: "SYSTEM INIT".to_string(),
|
value: label_entry_addr.into(),
|
||||||
timestamp: chrono::Utc::now().naive_utc(),
|
provenance: "SYSTEM INIT".to_string(),
|
||||||
user: context.user.clone(),
|
timestamp: chrono::Utc::now().naive_utc(),
|
||||||
};
|
user: context.user.clone(),
|
||||||
connection.insert_entry(alias_entry)?;
|
};
|
||||||
|
connection.insert_entry(alias_entry)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(blob_address)
|
Ok(blob_address)
|
||||||
|
|
Loading…
Reference in a new issue