Skip to content

Commit

Permalink
tuftool: Write create subcommand
Browse files Browse the repository at this point in the history
Signed-off-by: iliana destroyer of worlds <iweller@amazon.com>
  • Loading branch information
iliana committed Nov 8, 2019
1 parent 054fcaa commit a369010
Show file tree
Hide file tree
Showing 8 changed files with 610 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
@@ -1,3 +1,2 @@
/target
**/*.rs.bk
Cargo.lock
5 changes: 5 additions & 0 deletions Cargo.toml
Expand Up @@ -3,4 +3,9 @@ members = [
"olpc-cjson",
"tough",
"tough_schema",
"tuftool",
]

[profile.release]
debug = 1
lto = true
26 changes: 26 additions & 0 deletions tuftool/Cargo.toml
@@ -0,0 +1,26 @@
[package]
name = "tuftool"
version = "0.1.0"
description = "Utility for creating and signing The Update Framework (TUF) repositories"
authors = ["iliana destroyer of worlds <iweller@amazon.com>"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/awslabs/tough"
keywords = ["tuf", "update", "repository"]
edition = "2018"

[dependencies]
chrono = "0.4.6"
digest = "0.8.1"
hex = "0.3.2"
maplit = "1.0.1"
pem = "0.6.0"
rayon = "1.1"
ring = { version = "0.16.7", features = ["std"] }
serde = "1.0.99"
serde_json = "1.0.39"
sha2 = "0.8.0"
snafu = { version = "0.5.0", features = ["backtrace-crate"] }
structopt = "0.2.18"
tough_schema = { version = "0.1.0", path = "../tough_schema" }
olpc-cjson = { version = "0.1.0", path = "../olpc-cjson" }
walkdir = "2.2.9"
50 changes: 50 additions & 0 deletions tuftool/src/copylike.rs
@@ -0,0 +1,50 @@
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT OR Apache-2.0

use std::fmt::{self, Display};
use std::fs::{self};
use std::path::Path;

#[derive(Debug, Clone, Copy)]
pub(crate) enum Copylike {
Copy,
Hardlink,
Symlink,
}

impl Copylike {
pub(crate) fn run<P: AsRef<Path>, Q: AsRef<Path>>(self, src: P, dst: Q) -> std::io::Result<()> {
if let Some(parent) = dst.as_ref().parent() {
fs::create_dir_all(parent)?;
}
match self {
Copylike::Copy => fs::copy(src, dst).map(|_| ()),
Copylike::Hardlink => fs::hard_link(src, dst),
Copylike::Symlink => {
#[cfg(unix)]
{
std::os::unix::fs::symlink(src, dst)
}

#[cfg(windows)]
{
std::os::windows::fs::symlink_file(src, dst)
}
}
}
}
}

impl Display for Copylike {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"{}",
match self {
Copylike::Copy => "copy",
Copylike::Hardlink => "hardlink",
Copylike::Symlink => "symlink",
}
)
}
}

0 comments on commit a369010

Please sign in to comment.