Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly manage timestamps of profile files #89

Merged
merged 14 commits into from
Apr 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: apply clippy auto-fixes
  • Loading branch information
MrHedmad committed Apr 8, 2024
commit b3e43536bc03b3f9e16e34202a63e8d7b2d8b715
2 changes: 1 addition & 1 deletion src/commands/package.rs
Original file line number Diff line number Diff line change
@@ -132,7 +132,7 @@ pub fn package_pipe(config: KerblamTomlOptions, pipe: Pipe, package_name: &str)

// Create the 'name' file
let name_file = temp_package.path().join("name");
let mut name_file_conn = File::create(&name_file)?;
let mut name_file_conn = File::create(name_file)?;
write!(name_file_conn, "{}", package_name)?;

let package = here.join(format!("{}.kerblam.tar", pipe_name));
2 changes: 1 addition & 1 deletion src/commands/replay.rs
Original file line number Diff line number Diff line change
@@ -79,7 +79,7 @@ pub fn replay(
package_config.input_data_dir()
);
let data = gunzip_file(&data_archive, &data_archive)?;
let data_archive_conn = File::open(&data)?;
let data_archive_conn = File::open(data)?;
let mut data_archive = tar::Archive::new(data_archive_conn);
data_archive.unpack(package_config.input_data_dir())?;
};
5 changes: 2 additions & 3 deletions src/commands/run.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use log;
use std::collections::HashMap;
use std::env::current_dir;
use std::fs::read_to_string;
@@ -103,9 +102,9 @@ pub fn check_last_profile(current_profile: String) -> Option<bool> {
write_cache(&current_profile).unwrap();

if last_profile.is_none() {
return None;
None
} else {
return Some(result);
Some(result)
}
}

4 changes: 2 additions & 2 deletions src/execution.rs
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ use crate::options::KerblamTomlOptions;

use anyhow::{anyhow, bail, Context, Result};
use crossbeam_channel::{bounded, Receiver};
use ctrlc;

use filetime::{set_file_mtime, FileTime};

// TODO: I think we can add all cleanup code to `Drop`, so that a lot of these
@@ -181,7 +181,7 @@ impl Executor {

if extra_args.is_some() {
log::debug!("Appending extra command arguments...");
command_args.extend(extra_args.unwrap().into_iter());
command_args.extend(extra_args.unwrap());
}

log::debug!("Executor command arguments: {:?}", command_args);
10 changes: 4 additions & 6 deletions src/options.rs
Original file line number Diff line number Diff line change
@@ -216,12 +216,10 @@ impl Display for Pipe {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let container_prefix = if self.env_path.is_none() {
"◾"
} else if self.env_path.clone().unwrap().file_stem().unwrap() == "default" {
"🐟"
} else {
if self.env_path.clone().unwrap().file_stem().unwrap() == "default" {
"🐟"
} else {
"🐋"
}
"🐋"
};
let desc_prefix = if self
.description()
@@ -416,7 +414,7 @@ impl KerblamTomlOptions {
let default_dockerfile: Option<PathBuf> = envs_names
.iter()
.find(|(name, _)| name == "default")
.and_then(|(_, path)| Some(path.to_owned()));
.map(|(_, path)| path.to_owned());

for (pipe_name, pipe_path) in pipes_names {
let mut found = false;
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
@@ -432,7 +432,7 @@ pub fn tar_files(files: Vec<PathBuf>, strip: impl AsRef<Path>, target: PathBuf)
let mut data_tarball = tar::Builder::new(data_conn);

for item in files {
let inner = item.strip_prefix(&strip)?;
let inner = item.strip_prefix(strip)?;
log::debug!("Adding {item:?} as {inner:?} to {data_tar:?}...");
data_tarball.append_path_with_name(&item, inner)?;
}
6 changes: 2 additions & 4 deletions tests/run_local_examples.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use git2;
use paste;
use std::collections::HashMap;
use std::env::set_current_dir;
use std::mem::drop;
@@ -8,7 +6,7 @@ use std::process::Command;
use std::{fs, io};
use tempfile::TempDir;

const EXAMPLE_REPO: &'static str = "https://github.com/MrHedmad/kerblam-examples.git";
const EXAMPLE_REPO: &str = "https://github.com/MrHedmad/kerblam-examples.git";

/// Setup local tests by cloning the example repo.
fn setup_test() -> TempDir {
@@ -22,7 +20,7 @@ fn setup_test() -> TempDir {
fetcher.fetch_options(clone_options);

fetcher
.clone(EXAMPLE_REPO, &target.path())
.clone(EXAMPLE_REPO, target.path())
.expect("Could not clone remote repo.");

target
24 changes: 12 additions & 12 deletions tests/test_run.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::utils::{assert_ok, init_log, setup_workdir, File};
use chwd;

use kerblam::kerblam;
use rusty_fork::rusty_fork_test;

@@ -18,7 +18,7 @@ use rusty_fork::rusty_fork_test;
//
// Keep that in mind.

static TEST_KERBLAM_TOML: &'static str = r#"
static TEST_KERBLAM_TOML: &str = r#"
[data.remote]
"https://raw.githubusercontent.com/MrHedmad/kerblam/main/README.md" = "input_data.txt"
"https://raw.githubusercontent.com/BurntSushi/ripgrep/master/README.md" = "alternate_input_data.txt"
@@ -28,18 +28,18 @@ static TEST_KERBLAM_TOML: &'static str = r#"

"#;

static TEST_SHELL_PIPE: &'static str = r#"
static TEST_SHELL_PIPE: &str = r#"
echo "Running shell pipe"
mkdir -p ./data/out/
cat ./data/in/input_data.txt | wc -l > ./data/out/line_count.txt
"#;

static TEST_ERROR_SHELL_PIPE: &'static str = r#"
static TEST_ERROR_SHELL_PIPE: &str = r#"
echo "Running error shell pipe"
exit 1
"#;

static TEST_MAKE_PIPE: &'static str = r#"
static TEST_MAKE_PIPE: &str = r#"
.RECIPEPREFIX = >
all: ./data/out/line_count.txt

@@ -50,7 +50,7 @@ all: ./data/out/line_count.txt

"#;

static TEST_DOCKER_FILE: &'static str = r#"
static TEST_DOCKER_FILE: &str = r#"
FROM ubuntu:latest

COPY . .
@@ -74,8 +74,8 @@ rusty_fork_test! {
let temp_dir = setup_workdir(default_files.iter());
let _flag = chwd::ChangeWorkingDirectory::change(&temp_dir).unwrap();

assert_ok(kerblam(vec!["", "data", "fetch"].iter()));
assert_ok(kerblam(vec!["", "run", "shell_pipe", "--local"].iter()));
assert_ok(kerblam(["", "data", "fetch"].iter()));
assert_ok(kerblam(["", "run", "shell_pipe", "--local"].iter()));
}
}

@@ -87,8 +87,8 @@ rusty_fork_test! {
let temp_dir = setup_workdir(default_files.iter());
let _flag = chwd::ChangeWorkingDirectory::change(&temp_dir).unwrap();

assert_ok(kerblam(vec!["", "data", "fetch"].iter()));
assert_ok(kerblam(vec!["", "run", "make_pipe", "--local"].iter()));
assert_ok(kerblam(["", "data", "fetch"].iter()));
assert_ok(kerblam(["", "run", "make_pipe", "--local"].iter()));
}
}

@@ -101,7 +101,7 @@ rusty_fork_test! {
let temp_dir = setup_workdir(default_files.iter());
let _flag = chwd::ChangeWorkingDirectory::change(&temp_dir).unwrap();

assert_ok(kerblam(vec!["", "data", "fetch"].iter()));
assert_ok(kerblam(vec!["", "run", "error", "--local"].iter()));
assert_ok(kerblam(["", "data", "fetch"].iter()));
assert_ok(kerblam(["", "run", "error", "--local"].iter()));
}
}