Skip to content

Commit

Permalink
support long filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
the8472 committed Jul 1, 2017
1 parent 795d87d commit f74dd04
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 35 deletions.
44 changes: 22 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fastar"
version = "0.1.3"
version = "0.1.4"
authors = ["The8472"]
description = "Fast tar archive creation for HDDs"
keywords = ["linux", "cli", "tar", "archive"]
Expand All @@ -26,8 +26,8 @@ debug = false
[dependencies]
clap = "2.20"
derive-error = "0.0.3"
isatty = "0.1.3"
tar = "0.4.11"
nix = "0.8.1"
tar = "0.4.13"
reapfrog = "0.2.0"
platter-walk = "0.1.2"

Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ Optimizations compared to gnu tar:

* directory traversal based on physical disk layout. see [platter-walk](https://github.com/the8472/platter-walk) crate
* readaheads across multiple files at once to keep the drive's command queue filled. see [reapfrog](https://github.com/the8472/reapfrog) crate
* drops disk caches for files onces they are read to prevent disk buffer thrashing.
* drops disk caches for files once they are read to prevent disk buffer thrashing.


Current limitations:

* arguments must be directories
* only archives regular files, not symlinks
* filenames longer than 100 bytes are not supported (implementation isn't difficult, just the `tar-rs` API being clunky)
* only archives regular files, not symlinks or empty directories

## Benchmarks

Expand Down
28 changes: 21 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,30 @@ extern crate alloc_system;
extern crate reapfrog;
extern crate platter_walk;
extern crate tar;
extern crate nix;

use std::error::Error;
use std::io::*;
use std::path::Path;
use clap::{Arg, App};
use platter_walk::*;
use std::fs::File;
use tar::{Builder, Header, HeaderMode};
use std::os::unix::io::{FromRawFd, AsRawFd};

#[derive(Debug, Error)]
enum CliError {
Io(std::io::Error)
Io(std::io::Error),
Nix(nix::Error),
OutputIsATty
}


fn process_args() -> std::result::Result<(), CliError> {
let matches = App::new("fast file counting")
let matches = App::new("fast tar archive creator")
.version(crate_version!())
.arg(Arg::with_name("ord").long("leaf-order").required(false).takes_value(true).possible_values(&["inode","content", "dentry"]).help("optimize order for listing/stat/reads"))
.arg(Arg::with_name("out").short("f").required(false).takes_value(true).help("write output to file instead of stdout"))
.arg(Arg::with_name("dirs").index(1).multiple(true).required(false).help("directories to traverse [default: cwd]"))
.get_matches();

Expand Down Expand Up @@ -74,9 +80,18 @@ fn process_args() -> std::result::Result<(), CliError> {
let mut reap = reapfrog::MultiFileReadahead::new(it);
reap.dropbehind(true);

let out = std::io::stdout();
let locked = out.lock();
let mut builder = Builder::new(locked);
const STDOUT : i32 = 1;

let out = match matches.value_of("out") {
Some(s) => std::fs::OpenOptions::new().create(true).write(true).open(s)?,
None => unsafe { File::from_raw_fd(STDOUT) }
};

if nix::unistd::isatty(out.as_raw_fd())? {
return Err(CliError::OutputIsATty)
}

let mut builder = Builder::new(BufWriter::new(out));

loop {
match reap.next() {
Expand All @@ -96,9 +111,8 @@ fn process_args() -> std::result::Result<(), CliError> {

let mut header = Header::new_gnu();
header.set_metadata_in_mode(&reader.metadata(), HeaderMode::Deterministic);
header.set_path(p)?;
header.set_cksum();
builder.append(&header, &mut reader)?
builder.append_data(&mut header, &p, &mut reader)?
}
}

Expand Down

0 comments on commit f74dd04

Please sign in to comment.