Skip to content

Commit

Permalink
Merge pull request #613 from woshilapin/ntfs2ntfs
Browse files Browse the repository at this point in the history
[feature] Add 'ntfs2ntfs' binary
  • Loading branch information
ArnaudOggy authored Apr 23, 2020
2 parents 329175b + cf5dfc4 commit 2fa832d
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ members = [
"gtfs2ntfs",
"ntfs2gtfs",
"ntfs2netexfr",
"ntfs2ntfs",
]

[features]
Expand Down
24 changes: 24 additions & 0 deletions ntfs2ntfs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "ntfs2ntfs"
version = "1.0.0"
authors = ["Kisio Digital <[email protected]>"]
license = "AGPL-3.0-only"
description = "Binary to check and clean a NTFS"
edition = "2018"
homepage = "https://github.com/CanalTP/transit_model"
readme = "README.md"
categories = ["command-line-utilities", "data-structures", "encoding", "parser-implementations"]
keywords = ["ntfs", "transit"]

[dependencies]
chrono = "0.4"
failure = "0.1"
log = "0.4"
slog = "2.5"
slog-async = "2.3"
slog-envlogger = "2.1"
slog-scope = "4.1"
slog-stdlog = "4.0"
slog-term = "2.4"
structopt = "0.3"
transit_model = { version = "0.17", path = "../" }
24 changes: 24 additions & 0 deletions ntfs2ntfs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
`ntfs2ntfs`
=====

Command-Line Interface to check and clean a [NTFS] data format into data format.

[NTFS]: https://github.com/CanalTP/ntfs-specification/blob/master/ntfs_fr.md

# Installation
To install, use

```bash
cargo install ntfs2ntfs
```

# Usage

```bash
ntfs2ntfs --input /path/to/ntfs/folder/ --output /path/to/ntfs/
```

- `--input` is the path to a folder containing NTFS data format
- `--output` is the path to a folder where the NTFS will be exported

Get more information about the available options with `--help`.
84 changes: 84 additions & 0 deletions ntfs2ntfs/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright 2017 Kisio Digital and/or its affiliates.
//
// This program is free software: you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see
// <http://www.gnu.org/licenses/>.

use chrono::{DateTime, FixedOffset};
use log::info;
use slog::{slog_o, Drain};
use slog_async::OverflowStrategy;
use std::path::PathBuf;
use structopt::StructOpt;
use transit_model::Result;

#[derive(Debug, StructOpt)]
#[structopt(name = "ntfs2ntfs", about = "Convert an NTFS to an NTFS.")]
struct Opt {
/// input directory.
#[structopt(short = "i", long = "input", parse(from_os_str), default_value = ".")]
input: PathBuf,

/// output directory
#[structopt(short = "o", long = "output", parse(from_os_str))]
output: Option<PathBuf>,

/// current datetime
#[structopt(
short = "x",
long,
parse(try_from_str),
default_value = &transit_model::CURRENT_DATETIME
)]
current_datetime: DateTime<FixedOffset>,
}

fn init_logger() -> slog_scope::GlobalLoggerGuard {
let decorator = slog_term::TermDecorator::new().stdout().build();
let drain = slog_term::CompactFormat::new(decorator).build().fuse();
let mut builder = slog_envlogger::LogBuilder::new(drain).filter(None, slog::FilterLevel::Info);
if let Ok(s) = std::env::var("RUST_LOG") {
builder = builder.parse(&s);
}
let drain = slog_async::Async::new(builder.build())
.chan_size(256) // Double the default size
.overflow_strategy(OverflowStrategy::Block)
.build()
.fuse();
let logger = slog::Logger::root(drain, slog_o!());

let scope_guard = slog_scope::set_global_logger(logger);
slog_stdlog::init().unwrap();
scope_guard
}

fn run(opt: Opt) -> Result<()> {
info!("Launching ntfs2ntfs...");

let objects = transit_model::ntfs::read(opt.input)?;

if let Some(output) = opt.output {
transit_model::ntfs::write(&objects, output, opt.current_datetime)?;
}
Ok(())
}

fn main() {
let _log_guard = init_logger();
if let Err(err) = run(Opt::from_args()) {
for cause in err.iter_chain() {
eprintln!("{}", cause);
}
std::process::exit(1);
}
}

0 comments on commit 2fa832d

Please sign in to comment.