diff options
| author | metamuffin <metamuffin@disroot.org> | 2025-12-11 03:25:56 +0100 |
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2025-12-11 03:25:56 +0100 |
| commit | 214b78c581319ee012383134107fa5c371febe09 (patch) | |
| tree | 6d775bbeb54a78c1acc32694dda4b7c21e94219e /cache/src/bin | |
| parent | cd8a77b37fff75d7f2c3e96cf8a58598936b4e04 (diff) | |
| download | jellything-214b78c581319ee012383134107fa5c371febe09.tar jellything-214b78c581319ee012383134107fa5c371febe09.tar.bz2 jellything-214b78c581319ee012383134107fa5c371febe09.tar.zst | |
rocksdb cache backend
Diffstat (limited to 'cache/src/bin')
| -rw-r--r-- | cache/src/bin/cache_fs_to_rocksdb.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/cache/src/bin/cache_fs_to_rocksdb.rs b/cache/src/bin/cache_fs_to_rocksdb.rs new file mode 100644 index 0000000..0a3b43d --- /dev/null +++ b/cache/src/bin/cache_fs_to_rocksdb.rs @@ -0,0 +1,37 @@ +/* + 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) 2025 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())?; + 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(()) +} |