fix: don't needlessly insert hashy filename

feat/type-attributes
Tomáš Mládek 2023-05-27 16:06:22 +02:00
parent 0666076045
commit bd0f74b658
1 changed files with 15 additions and 4 deletions

View File

@ -339,6 +339,7 @@ impl FsStore {
&db.borrow().connection()?,
&normalized_path,
file_hash.unwrap(),
None,
size,
mtime,
mime_type,
@ -350,7 +351,13 @@ impl FsStore {
})
}
fn add_file(&self, connection: &UpEndConnection, path: &Path, hash: Hash) -> Result<Address> {
fn add_file(
&self,
connection: &UpEndConnection,
path: &Path,
hash: Hash,
name_hint: Option<String>,
) -> Result<Address> {
let normalized_path = self.normalize_path(path)?;
let metadata = fs::metadata(path)?;
let size = metadata.len() as i64;
@ -370,6 +377,7 @@ impl FsStore {
connection,
&normalized_path,
hash,
name_hint,
size,
mtime,
mime_type,
@ -383,6 +391,7 @@ impl FsStore {
connection: &UpEndConnection,
normalized_path: &Path,
hash: Hash,
name: Option<String>,
size: i64,
mtime: Option<NaiveDateTime>,
mime_type: Option<String>,
@ -479,7 +488,9 @@ impl FsStore {
let label_entry = Entry {
entity: blob_address.clone(),
attribute: LABEL_ATTR.to_string(),
value: filename.as_os_str().to_string_lossy().to_string().into(),
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(),
};
@ -643,7 +654,7 @@ impl UpStore for FsStore {
.map_err(|e| StoreError::Unknown(e.to_string()))?,
);
let final_name = if let Some(name_hint) = name_hint {
let final_name = if let Some(name_hint) = &name_hint {
format!("{addr_str}_{name_hint}")
} else {
addr_str
@ -653,7 +664,7 @@ impl UpStore for FsStore {
fs::copy(file_path, &final_path).map_err(|e| StoreError::Unknown(e.to_string()))?;
self.add_file(&connection, &final_path, hash.clone())
self.add_file(&connection, &final_path, hash.clone(), name_hint)
.map_err(|e| StoreError::Unknown(e.to_string()))?;
}