Skip to content
Permalink
Browse files

tuftool: Write create subcommand

Signed-off-by: iliana destroyer of worlds <iweller@amazon.com>
  • Loading branch information
iliana committed Aug 27, 2019
1 parent 054fcaa commit a369010f66c0bb0c0569e2f66da00710e5edb6c6
Showing with 610 additions and 1 deletion.
  1. +0 −1 .gitignore
  2. +5 −0 Cargo.toml
  3. +26 −0 tuftool/Cargo.toml
  4. +50 −0 tuftool/src/copylike.rs
  5. +321 −0 tuftool/src/create.rs
  6. +110 −0 tuftool/src/error.rs
  7. +51 −0 tuftool/src/key.rs
  8. +47 −0 tuftool/src/main.rs
@@ -1,3 +1,2 @@
/target
**/*.rs.bk
Cargo.lock
@@ -3,4 +3,9 @@ members = [
"olpc-cjson",
"tough",
"tough_schema",
"tuftool",
]

[profile.release]
debug = 1
lto = true
@@ -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"
@@ -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.
You can’t perform that action at this time.