Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Crunch
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Microhacks
Crunch
Commits
17ebe9bd
Verified
Commit
17ebe9bd
authored
2 years ago
by
Louis
Browse files
Options
Downloads
Patches
Plain Diff
Special case empty actions array to do a direct file copy
parent
6aa6cfc7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
source-install.sh
+3
-3
3 additions, 3 deletions
source-install.sh
src/commands/pipeline.rs
+38
-14
38 additions, 14 deletions
src/commands/pipeline.rs
src/format.rs
+8
-0
8 additions, 0 deletions
src/format.rs
with
49 additions
and
17 deletions
source-install.sh
+
3
−
3
View file @
17ebe9bd
#!/usr/bin/env sh
cargo build
--release
strip release/target/crunch
chmod
u+x release/target/crunch
cp
release/target/crunch
"
$HOME
/.local/bin/crunch"
\ No newline at end of file
strip target/release/crunch
chmod
u+x target/release/crunch
cp
target/release/crunch
"
$HOME
/.local/bin/crunch"
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/commands/pipeline.rs
+
38
−
14
View file @
17ebe9bd
use
glob
::{
glob_with
,
MatchOptions
};
use
std
::
collections
::
HashMap
;
use
std
::
path
::{
Path
,
PathBuf
};
...
...
@@ -7,6 +6,7 @@ use serde::{Deserialize, Serialize};
use
thiserror
::
Error
;
use
crate
::
cli_args
::
CrunchCommand
;
use
crate
::
format
::
make_paths
;
use
crate
::{
commands
,
load_image
};
#[derive(Error,
Debug)]
...
...
@@ -50,19 +50,44 @@ pub fn execute_pipeline<IN: ToString, OUT: ToString>(
file_path
:
IN
,
_outpath
:
OUT
,
)
->
anyhow
::
Result
<
()
>
{
let
path
=
file_path
.to_string
();
if
!&
path
.ends_with
(
".toml"
)
&&
!&
path
.ends_with
(
".json"
)
{
let
path
=
std
::
env
::
current_dir
()
.map
(|
path
|
path
.join
(
file_path
.to_string
()))
?
;
let
path_string
=
format!
(
"{}"
,
&
path
.display
());
log
::
debug!
(
"Trying to read from input file: {}"
,
&
path
.display
());
if
!&
path_string
.ends_with
(
".toml"
)
&&
!&
path_string
.ends_with
(
".json"
)
{
Err
(
PipelineError
::
FormatDetection
)
?
;
}
let
file_contents
=
std
::
fs
::
read
(
file_path
.to_string
())
?
;
let
pipeline_data
:
PipelineFile
=
if
path
.ends_with
(
".toml"
)
{
let
file_contents
=
std
::
fs
::
read
(
path
)
?
;
log
::
debug!
(
"Found correct file type and read bytes, trying to parse"
);
let
pipeline_data
:
PipelineFile
=
if
path_string
.ends_with
(
".toml"
)
{
toml
::
from_slice
(
&
file_contents
)
?
}
else
{
serde_json
::
from_slice
(
&
file_contents
)
?
};
log
::
debug!
(
"Expanding pipeline file into targets"
);
get_targets
(
&
pipeline_data
)
.for_each
(|(
input_path
,
output_path
,
actions
)|
{
match
make_paths
(
&
output_path
)
{
Ok
(
_
)
=>
{}
Err
(
e
)
=>
{
log
::
error!
(
"Failed to create target directory {}; {}"
,
&
output_path
,
e
);
return
;
}
}
if
actions
.is_empty
()
{
match
std
::
fs
::
copy
(
&
input_path
,
&
output_path
)
{
Ok
(
_
)
=>
{}
Err
(
e
)
=>
{
log
::
error!
(
"Failed to copy {} to {}; {}"
,
input_path
,
output_path
,
e
);
}
};
return
;
}
let
mut
file
=
match
load_image
(
&
input_path
,
None
)
{
Ok
(
image
)
=>
image
,
Err
(
e
)
=>
{
...
...
@@ -71,6 +96,11 @@ pub fn execute_pipeline<IN: ToString, OUT: ToString>(
}
};
log
::
debug!
(
"Loaded {}, Executing {} actions"
,
&
input_path
,
actions
.len
()
);
let
mut
count
=
1
;
for
step
in
actions
{
match
step
{
...
...
@@ -248,15 +278,9 @@ fn get_targets(
.map
(|
value
|
(
*
value
)
.actions
.clone
())
.flat_map
(|
actions
|
{
let
mut
paths
=
Vec
::
new
();
for
entry
in
glob_with
(
pattern
.as_str
(),
MatchOptions
{
case_sensitive
:
true
,
..
Default
::
default
()
},
)
.unwrap
()
{
log
::
debug!
(
"Mapping glob paths for '{}'"
,
pattern
.as_str
());
for
entry
in
glob
::
glob
(
pattern
.as_str
())
.unwrap
()
{
log
::
debug!
(
"Found a glob match: [{:?}]"
,
entry
);
paths
.push
((
actions
.clone
(),
entry
));
}
paths
...
...
This diff is collapsed.
Click to expand it.
src/format.rs
+
8
−
0
View file @
17ebe9bd
...
...
@@ -64,3 +64,11 @@ pub fn load_image<T: AsRef<Path>>(
Ok
(
file
)
}
pub
fn
make_paths
<
T
:
AsRef
<
Path
>>
(
path
:
T
)
->
anyhow
::
Result
<
(),
std
::
io
::
Error
>
{
if
let
Some
(
target
)
=
path
.as_ref
()
.parent
()
{
std
::
fs
::
create_dir_all
(
target
)
}
else
{
Ok
(())
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment