diff options
| author | jakka <jakkadoujin@gmail.com> | 2025-06-19 11:14:37 +0300 |
|---|---|---|
| committer | jakka <jakkadoujin@gmail.com> | 2025-06-19 11:14:37 +0300 |
| commit | aa95671996bc55f69305505c5da2e715a85da189 (patch) | |
| tree | fd666125fb8532969e112cd07c9b44025183acf7 /src | |
| parent | 024c3b3c06e6437977e884fb100489aa67d086fd (diff) | |
cleaned up abspath
Diffstat (limited to 'src')
| -rw-r--r-- | src/db.rs | 23 | ||||
| -rw-r--r-- | src/files.rs | 10 |
2 files changed, 13 insertions, 20 deletions
@@ -32,10 +32,9 @@ impl Database { } pub async fn insert_file(&self, filename: impl AsRef<Path>) -> Result<()> { - let abs_filename = filename.as_ref().canonicalize()?; - let toencode = !matches!(get_vendor(&abs_filename)?.as_str(), CURRENT_VENDOR); + let toencode = !matches!(get_vendor(&filename)?.as_str(), CURRENT_VENDOR); - let modtime = abs_filename + let modtime = filename.as_ref() .metadata()? .modified()? .duration_since(UNIX_EPOCH)? @@ -44,7 +43,7 @@ impl Database { self.0 .execute( ADD_NEW_ITEM, - params![abs_filename.to_str().unwrap(), toencode, modtime], + params![filename.as_ref().to_str().unwrap(), toencode, modtime], ) .await?; @@ -52,9 +51,7 @@ impl Database { } pub async fn update_file(&self, filename: impl AsRef<Path>) -> Result<()> { - let abs_filename = filename.as_ref().canonicalize()?; - - let modtime = abs_filename + let modtime = filename.as_ref() .metadata()? .modified()? .duration_since(UNIX_EPOCH)? @@ -63,7 +60,7 @@ impl Database { self.0 .execute( REPLACE_ITEM, - params![abs_filename.to_str().unwrap(), false, modtime], + params![filename.as_ref().to_str().unwrap(), false, modtime], ) .await?; @@ -71,11 +68,9 @@ impl Database { } pub async fn check_file(&self, filename: impl AsRef<Path>) -> Result<bool> { - let abs_filename = filename.as_ref().canonicalize()?; - if let Some(row) = self .0 - .query(CHECK_FILE, params!(abs_filename.to_str().unwrap())) + .query(CHECK_FILE, params!(filename.as_ref().to_str().unwrap())) .await? .next() .await? @@ -87,11 +82,9 @@ impl Database { } pub async fn get_modtime(&self, filename: impl AsRef<Path>) -> Result<u64> { - let abs_filename = filename.as_ref().canonicalize()?; - if let Some(row) = self .0 - .query(FETCH_MODTIME, params!(abs_filename.to_str().unwrap())) + .query(FETCH_MODTIME, params!(filename.as_ref().to_str().unwrap())) .await? .next() .await? @@ -111,7 +104,7 @@ impl Database { self.0.execute(DEDUPE_DB, ()).await?; let mut query_res = self.0.query(FETCH_FILES, ()).await?; while let Ok(Some(row)) = query_res.next().await { - let path = Path::new(row.get_str(0)?).canonicalize()?; + let path = Path::new(row.get_str(0)?).to_path_buf(); let conn = self.0.clone(); tasks.spawn(async move { if !path.exists() { diff --git a/src/files.rs b/src/files.rs index 743e489..045c5b4 100644 --- a/src/files.rs +++ b/src/files.rs @@ -105,16 +105,16 @@ pub async fn index_files_recursively(path: impl AsRef<Path>, conn: &Database) -> Ok(()) } -fn check_path(folderpath: Option<&PathBuf>) -> (PathBuf, bool) { +fn check_path(folderpath: Option<&PathBuf>) -> Result<(PathBuf, bool)> { if let Some(real_path) = folderpath { - (real_path.to_owned(), false) + Ok((real_path.canonicalize()?, false)) } else { - (PathBuf::new(), true) + Ok((PathBuf::new(), true)) } } pub async fn reencode_files(folderpath: Option<&PathBuf>, conn: &Database) -> Result<()> { - let (path, nocheck) = check_path(folderpath); + let (path, nocheck) = check_path(folderpath)?; let stream = conn.get_toencode_stream().await?; pin_mut!(stream); @@ -159,7 +159,7 @@ pub async fn reencode_files(folderpath: Option<&PathBuf>, conn: &Database) -> Re } pub async fn count_reencode_files(folderpath: Option<&PathBuf>, conn: &Database) -> Result<u64> { - let (path, nocheck) = check_path(folderpath); + let (path, nocheck) = check_path(folderpath)?; let mut counter: u64 = 0; let stream = conn.get_toencode_stream().await?; |
