Skip to content

Commit

Permalink
Fix path error on initial run (#313)
Browse files Browse the repository at this point in the history
Fixes #312 

This isn't idiomatic but it'll do for the time being
  • Loading branch information
denisidoro authored Mar 24, 2020
1 parent 6ed7cd1 commit 6515466
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "navi"
version = "2.4.0"
version = "2.4.1"
authors = ["Denis Isidoro <[email protected]>"]
edition = "2018"
description = "An interactive cheatsheet tool for the command-line"
Expand Down
8 changes: 6 additions & 2 deletions scripts/docker
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ export NAVI_HOME="$(cd "$(dirname "$0")/.." && pwd)"

cd "$NAVI_HOME"

./scripts/action release x86_64-unknown-linux-musl

docker run \
-e HOMEBREW_NO_AUTO_UPDATE=1 \
-it linuxbrew/alpine \
bash -c 'brew install denisidoro/tools/navirs; bash'
-e HOMEBREW_NO_INSTALL_CLEANUP=1 \
-v "$(pwd):/navi" \
-it 'bashell/alpine-bash' \
bash -c 'apk add git; apk add curl; git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf && yes | ln -s /navi/target/debug/navi /usr/local/bin/navi; source $HOME/.bashrc; bash'
2 changes: 1 addition & 1 deletion src/flows/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn add(uri: String) -> Result<(), Error> {
let tmp_path_str = filesystem::tmp_path_str()?;
let tmp_path_str_with_trailing_slash = format!("{}/", &tmp_path_str);

filesystem::remove_dir(&tmp_path_str)?;
let _ = filesystem::remove_dir(&tmp_path_str);
filesystem::create_dir(&tmp_path_str)?;

eprintln!("Cloning {} into {}...\n", &actual_uri, &tmp_path_str);
Expand Down
34 changes: 20 additions & 14 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ use crate::filesystem;
use crate::structures::cheat::VariableMap;
use crate::structures::fnv::HashLine;
use crate::structures::fzf::{Opts as FzfOpts, SuggestionType};
use crate::structures::{
error::filesystem::{InvalidPath, UnreadableDir},
option::Config,
};
use crate::structures::{error::filesystem::InvalidPath, option::Config};
use crate::welcome;
use anyhow::{Context, Error};
use regex::Regex;
Expand Down Expand Up @@ -226,21 +223,30 @@ pub fn read_all(
let mut variables = VariableMap::new();
let mut found_something = false;
let mut visited_lines = HashSet::new();
let paths = filesystem::cheat_paths(config)?;
let paths = filesystem::cheat_paths(config);

if paths.is_err() {
welcome::cheatsheet(stdin);
return Ok(variables);
}

let paths = paths.expect("Unable to get paths");
let folders = paths_from_path_param(&paths);

for folder in folders {
if let Ok(dir_entries) = fs::read_dir(folder) {
for entry in dir_entries {
let path = entry.map_err(|e| UnreadableDir::new(folder, e))?.path();
let path_str = path
.to_str()
.ok_or_else(|| InvalidPath(path.to_path_buf()))?;
if path_str.ends_with(".cheat")
&& read_file(path_str, &mut variables, &mut visited_lines, stdin).is_ok()
&& !found_something
{
found_something = true;
if entry.is_ok() {
let path = entry.expect("Impossible to read an invalid entry").path();
let path_str = path
.to_str()
.ok_or_else(|| InvalidPath(path.to_path_buf()))?;
if path_str.ends_with(".cheat")
&& read_file(path_str, &mut variables, &mut visited_lines, stdin).is_ok()
&& !found_something
{
found_something = true;
}
}
}
}
Expand Down

0 comments on commit 6515466

Please sign in to comment.