diff options
| author | metamuffin <metamuffin@disroot.org> | 2026-03-07 02:58:23 +0100 |
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2026-03-07 02:58:23 +0100 |
| commit | a93e0bf8db710ef9dcd40e1526ddd4b18a7288e9 (patch) | |
| tree | 96b40088f0922146a793405dc37e49d74e5af440 /kv/src/bin | |
| parent | d6287e2f54bd3ad22f970c0a3fe5230be00a592e (diff) | |
| download | jellything-a93e0bf8db710ef9dcd40e1526ddd4b18a7288e9.tar jellything-a93e0bf8db710ef9dcd40e1526ddd4b18a7288e9.tar.bz2 jellything-a93e0bf8db710ef9dcd40e1526ddd4b18a7288e9.tar.zst | |
move cache tools to kv crate
Diffstat (limited to 'kv/src/bin')
| -rw-r--r-- | kv/src/bin/fs_to_rocksdb.rs | 38 | ||||
| -rw-r--r-- | kv/src/bin/rocksdb_remove_prefix.rs | 25 |
2 files changed, 63 insertions, 0 deletions
diff --git a/kv/src/bin/fs_to_rocksdb.rs b/kv/src/bin/fs_to_rocksdb.rs new file mode 100644 index 0000000..d283dcb --- /dev/null +++ b/kv/src/bin/fs_to_rocksdb.rs @@ -0,0 +1,38 @@ +/* + This file is part of jellything (https://codeberg.org/metamuffin/jellything) + which is licensed under the GNU Affero General Public License (version 3); see /COPYING. + Copyright (C) 2026 metamuffin <metamuffin.org> +*/ + +use anyhow::{Result, bail}; +use rocksdb::DB; +use std::{env::args, fs::File, io::Read, path::Path}; + +fn main() -> Result<()> { + let in_path = args().nth(1).unwrap(); + let out_path = args().nth(2).unwrap(); + let db = DB::open_default(out_path)?; + if !in_path.ends_with("/") { + bail!("path needs to end with /") + } + traverse(&db, &in_path, in_path.as_ref())?; + db.flush()?; + Ok(()) +} + +fn traverse(db: &DB, prefix: &str, path: &Path) -> Result<()> { + if path.is_dir() { + for e in path.read_dir()? { + traverse(db, prefix, &e?.path())?; + } + } + if path.is_file() { + let key = path.to_string_lossy(); + let key = key.strip_prefix(prefix).unwrap(); + let mut value = Vec::new(); + File::open(path)?.read_to_end(&mut value)?; + println!("{key}"); + db.put(key, value)?; + } + Ok(()) +} diff --git a/kv/src/bin/rocksdb_remove_prefix.rs b/kv/src/bin/rocksdb_remove_prefix.rs new file mode 100644 index 0000000..e09ce61 --- /dev/null +++ b/kv/src/bin/rocksdb_remove_prefix.rs @@ -0,0 +1,25 @@ +/* + This file is part of jellything (https://codeberg.org/metamuffin/jellything) + which is licensed under the GNU Affero General Public License (version 3); see /COPYING. + Copyright (C) 2026 metamuffin <metamuffin.org> +*/ + +use anyhow::Result; +use rocksdb::DB; +use std::env::args; + +fn main() -> Result<()> { + let db = DB::open_default(args().nth(1).unwrap())?; + let prefix = args().nth(2).unwrap(); + for r in db.prefix_iterator(&prefix) { + let key = r?.0; + let key_s = String::from_utf8_lossy(&key); + if !key_s.starts_with(&prefix) { + break; + } + println!("{key_s}"); + db.delete(key)?; + } + db.flush()?; + Ok(()) +} |