aboutsummaryrefslogtreecommitdiff
path: root/cache/tools/cache_rocksdb_delete_prefix.rs
blob: e09ce61ec8bd695cc74b94d1aa425c445e0b561d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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(())
}