fix: don't needlessly insert hashy filename
parent
0666076045
commit
bd0f74b658
|
@ -339,6 +339,7 @@ impl FsStore {
|
||||||
&db.borrow().connection()?,
|
&db.borrow().connection()?,
|
||||||
&normalized_path,
|
&normalized_path,
|
||||||
file_hash.unwrap(),
|
file_hash.unwrap(),
|
||||||
|
None,
|
||||||
size,
|
size,
|
||||||
mtime,
|
mtime,
|
||||||
mime_type,
|
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 normalized_path = self.normalize_path(path)?;
|
||||||
let metadata = fs::metadata(path)?;
|
let metadata = fs::metadata(path)?;
|
||||||
let size = metadata.len() as i64;
|
let size = metadata.len() as i64;
|
||||||
|
@ -370,6 +377,7 @@ impl FsStore {
|
||||||
connection,
|
connection,
|
||||||
&normalized_path,
|
&normalized_path,
|
||||||
hash,
|
hash,
|
||||||
|
name_hint,
|
||||||
size,
|
size,
|
||||||
mtime,
|
mtime,
|
||||||
mime_type,
|
mime_type,
|
||||||
|
@ -383,6 +391,7 @@ impl FsStore {
|
||||||
connection: &UpEndConnection,
|
connection: &UpEndConnection,
|
||||||
normalized_path: &Path,
|
normalized_path: &Path,
|
||||||
hash: Hash,
|
hash: Hash,
|
||||||
|
name: Option<String>,
|
||||||
size: i64,
|
size: i64,
|
||||||
mtime: Option<NaiveDateTime>,
|
mtime: Option<NaiveDateTime>,
|
||||||
mime_type: Option<String>,
|
mime_type: Option<String>,
|
||||||
|
@ -479,7 +488,9 @@ impl FsStore {
|
||||||
let label_entry = Entry {
|
let label_entry = Entry {
|
||||||
entity: blob_address.clone(),
|
entity: blob_address.clone(),
|
||||||
attribute: LABEL_ATTR.to_string(),
|
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(),
|
provenance: "SYSTEM INIT".to_string(),
|
||||||
timestamp: chrono::Utc::now().naive_utc(),
|
timestamp: chrono::Utc::now().naive_utc(),
|
||||||
};
|
};
|
||||||
|
@ -643,7 +654,7 @@ impl UpStore for FsStore {
|
||||||
.map_err(|e| StoreError::Unknown(e.to_string()))?,
|
.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}")
|
format!("{addr_str}_{name_hint}")
|
||||||
} else {
|
} else {
|
||||||
addr_str
|
addr_str
|
||||||
|
@ -653,7 +664,7 @@ impl UpStore for FsStore {
|
||||||
|
|
||||||
fs::copy(file_path, &final_path).map_err(|e| StoreError::Unknown(e.to_string()))?;
|
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()))?;
|
.map_err(|e| StoreError::Unknown(e.to_string()))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue