Debian Codegraph @

third_party/rust/rkv/src/bin/dump.rs

raw
1 // Copyright 2018-2019 Mozilla
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 // this file except in compliance with the License. You may obtain a copy of the
5 // License at http://www.apache.org/licenses/LICENSE-2.0
6 // Unless required by applicable law or agreed to in writing, software distributed
7 // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
8 // CONDITIONS OF ANY KIND, either express or implied. See the License for the
9 // specific language governing permissions and limitations under the License.
10
11 use std::{env::args, io, path::Path};
12
13 use rkv::migrator::{LmdbArchMigrateError, LmdbArchMigrator};
14
15 fn main() -> Result<(), LmdbArchMigrateError> {
16 let mut cli_args = args();
17 let mut db_name = None;
18 let mut env_path = None;
19
20 // The first arg is the name of the program, which we can ignore.
21 cli_args.next();
22
23 while let Some(arg) = cli_args.next() {
24 if &arg[0..1] == "-" {
25 match &arg[1..] {
26 "s" => {
27 db_name = match cli_args.next() {
28 None => return Err("-s must be followed by database name".into()),
29 Some(str) => Some(str),
30 };
31 }
32 str => return Err(format!("arg -{str} not recognized").into()),
33 }
34 } else {
35 if env_path.is_some() {
36 return Err("must provide only one path to the LMDB environment".into());
37 }
38 env_path = Some(arg);
39 }
40 }
41
42 let env_path = env_path.ok_or("must provide a path to the LMDB environment")?;
43 let mut migrator = LmdbArchMigrator::new(Path::new(&env_path))?;
44 migrator.dump(db_name.as_deref(), io::stdout()).unwrap();
45
46 Ok(())
47 }