mirror of
https://github.com/PR0M3TH3AN/Marlin.git
synced 2025-09-09 07:38:50 +00:00
Format db modules
This commit is contained in:
@@ -22,6 +22,3 @@
|
|||||||
| `event add` | — |
|
| `event add` | — |
|
||||||
| `event timeline` | — |
|
| `event timeline` | — |
|
||||||
| `backup run` | --dir, --prune, --verify, --file |
|
| `backup run` | --dir, --prune, --verify, --file |
|
||||||
| `watch start` | --debounce-ms |
|
|
||||||
| `watch status` | — |
|
|
||||||
| `watch stop` | — |
|
|
||||||
|
@@ -188,7 +188,12 @@ pub fn ensure_tag_path(conn: &Connection, path: &str) -> Result<i64> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn file_id(conn: &Connection, path: &str) -> Result<i64> {
|
pub fn file_id(conn: &Connection, path: &str) -> Result<i64> {
|
||||||
conn.query_row("SELECT id FROM files WHERE path = ?1", [path], |r| r.get(0))
|
let path = to_db_path(path);
|
||||||
|
conn.query_row(
|
||||||
|
"SELECT id FROM files WHERE path = ?1",
|
||||||
|
[path.clone()],
|
||||||
|
|r| r.get(0),
|
||||||
|
)
|
||||||
.map_err(|_| anyhow::anyhow!("file not indexed: {}", path))
|
.map_err(|_| anyhow::anyhow!("file not indexed: {}", path))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -193,6 +193,7 @@ fn backup_and_restore_cycle() {
|
|||||||
|
|
||||||
// backup
|
// backup
|
||||||
let backup = db::backup(&db_path).unwrap();
|
let backup = db::backup(&db_path).unwrap();
|
||||||
|
drop(live); // close connection on Windows
|
||||||
// remove original
|
// remove original
|
||||||
std::fs::remove_file(&db_path).unwrap();
|
std::fs::remove_file(&db_path).unwrap();
|
||||||
// restore
|
// restore
|
||||||
|
@@ -13,7 +13,6 @@ use notify::{
|
|||||||
event::{ModifyKind, RemoveKind, RenameMode},
|
event::{ModifyKind, RemoveKind, RenameMode},
|
||||||
Event, EventKind, RecommendedWatcher, RecursiveMode, Watcher as NotifyWatcherTrait,
|
Event, EventKind, RecommendedWatcher, RecursiveMode, Watcher as NotifyWatcherTrait,
|
||||||
};
|
};
|
||||||
#[cfg(not(windows))]
|
|
||||||
use same_file::Handle;
|
use same_file::Handle;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
@@ -94,13 +93,12 @@ struct RemoveTracker {
|
|||||||
|
|
||||||
impl RemoveTracker {
|
impl RemoveTracker {
|
||||||
fn record(&mut self, path: &PathBuf) {
|
fn record(&mut self, path: &PathBuf) {
|
||||||
#[cfg(not(windows))]
|
|
||||||
if let Ok(h) = Handle::from_path(path) {
|
if let Ok(h) = Handle::from_path(path) {
|
||||||
self.map.insert(h.ino(), (path.clone(), Instant::now()));
|
self.map.insert(h.ino(), (path.clone(), Instant::now()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// fall back to hashing path if inode not available or on Windows
|
// fall back to hashing path if handle could not be obtained
|
||||||
use std::collections::hash_map::DefaultHasher;
|
use std::collections::hash_map::DefaultHasher;
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
let mut hasher = DefaultHasher::new();
|
let mut hasher = DefaultHasher::new();
|
||||||
@@ -110,7 +108,6 @@ impl RemoveTracker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn match_create(&mut self, path: &PathBuf, window: Duration) -> Option<PathBuf> {
|
fn match_create(&mut self, path: &PathBuf, window: Duration) -> Option<PathBuf> {
|
||||||
#[cfg(not(windows))]
|
|
||||||
if let Ok(h) = Handle::from_path(path) {
|
if let Ok(h) = Handle::from_path(path) {
|
||||||
if let Some((old, ts)) = self.map.remove(&h.ino()) {
|
if let Some((old, ts)) = self.map.remove(&h.ino()) {
|
||||||
if Instant::now().duration_since(ts) <= window {
|
if Instant::now().duration_since(ts) <= window {
|
||||||
@@ -121,7 +118,7 @@ impl RemoveTracker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fall back to hashing path when handle not available or on Windows
|
// fall back to hashing path when handle not available
|
||||||
use std::collections::hash_map::DefaultHasher;
|
use std::collections::hash_map::DefaultHasher;
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
let mut hasher = DefaultHasher::new();
|
let mut hasher = DefaultHasher::new();
|
||||||
|
Reference in New Issue
Block a user