File tree Expand file tree Collapse file tree 3 files changed +48
-20
lines changed
Expand file tree Collapse file tree 3 files changed +48
-20
lines changed Original file line number Diff line number Diff line change @@ -73,17 +73,19 @@ pub fn commands() -> Vec<Command> {
7373 . alias( "end" )
7474 . about( "Encrypt directory." )
7575 . args( [
76- arg!( <PATH > "Directory path (e.g. \" /home/user/important\" )." ) ,
77- arg!( --delete "Delete the origin files in the directory." ) ,
78- arg!( --key "Use custom key." )
76+ arg!( <PATH > "Directory path (e.g. \" /home/user/important\" )." ) ,
77+ arg!( --delete "Delete the origin files in the directory." ) ,
78+ arg!( --"no-threads" "Encrypt directory using the main thread only." ) ,
79+ arg!( --key "Use custom key." )
7980 ] ) ,
8081 Command :: new( "decrypt-dir" )
8182 . alias( "ded" )
8283 . about( "Decrypt directory." )
8384 . args( [
84- arg!( <PATH > "Directory path (e.g. \" /home/user/important\" )." ) ,
85- arg!( --delete "Delete the origin files in the directory." ) ,
86- arg!( --xpmv1 "Decrypt XPManager v1.0 directory." )
85+ arg!( <PATH > "Directory path (e.g. \" /home/user/important\" )." ) ,
86+ arg!( --delete "Delete the origin files in the directory." ) ,
87+ arg!( --"no-threads" "Decrypt directory using the main thread only." ) ,
88+ arg!( --xpmv1 "Decrypt XPManager v1.0 directory." )
8789 ] ) ,
8890 Command :: new( "encode" )
8991 . alias( "enc" )
Original file line number Diff line number Diff line change @@ -77,6 +77,7 @@ pub fn main(command: &ArgMatches) {
7777 let mut files_paths: Vec < PathBuf > = vec ! [ ] ;
7878 let is_xpmv1 = * command. get_one :: < bool > ( "xpmv1" ) . unwrap_or ( & false ) ;
7979 let is_delete = * command. get_one :: < bool > ( "delete" ) . unwrap_or ( & false ) ;
80+ let no_threads = * command. get_one :: < bool > ( "no-threads" ) . unwrap_or ( & false ) ;
8081 let key = utilities:: input ( "Enter your key: " ) ;
8182 logger. start ( ) ;
8283 filelib:: dir_files_tree (
@@ -96,18 +97,30 @@ pub fn main(command: &ArgMatches) {
9697 }
9798 logger. info ( "directory listed successfully." ) ;
9899
99- // Distribute files over the number of threads
100- let distributed_paths: Vec < Vec < PathBuf > > = utilities:: distribute_paths ( files_paths. clone ( ) ) ;
101-
102- // Run the threads
103- distributed_paths. par_iter ( ) . for_each ( |paths| {
100+ if no_threads {
101+ logger. info ( "start the decryption using the main thread." ) ;
104102 decrypt (
105- paths ,
103+ & files_paths ,
106104 key. clone ( ) ,
107105 is_delete,
108106 is_xpmv1
109107 ) ;
110- } ) ;
108+ } else {
109+ logger. info ( "start the decryption with the max number of threads." ) ;
110+ // Distribute files over the number of threads
111+ let distributed_paths: Vec < Vec < PathBuf > > = utilities:: distribute_paths ( files_paths. clone ( ) ) ;
112+
113+ // Run the threads
114+ distributed_paths. par_iter ( ) . for_each ( |paths| {
115+ decrypt (
116+ paths,
117+ key. clone ( ) ,
118+ is_delete,
119+ is_xpmv1
120+ ) ;
121+ } ) ;
122+ }
123+
111124 logger. info ( "directory decrypted successfully." ) ;
112125 displaylib:: key:: display ( key) ;
113126}
Original file line number Diff line number Diff line change @@ -68,6 +68,7 @@ pub fn main(command: &ArgMatches) {
6868 let mut logger = loglib:: Logger :: new ( "encrypt-dir" ) ;
6969 let path = command. get_one :: < String > ( "PATH" ) . unwrap ( ) ;
7070 let is_delete = * command. get_one :: < bool > ( "delete" ) . unwrap_or ( & false ) ;
71+ let no_threads = * command. get_one :: < bool > ( "no-threads" ) . unwrap_or ( & false ) ;
7172 let mut files_paths: Vec < PathBuf > = vec ! [ ] ;
7273 let key = if * command. get_one :: < bool > ( "key" )
7374 . unwrap_or ( & false ) {
@@ -102,18 +103,30 @@ pub fn main(command: &ArgMatches) {
102103 logger. start ( ) ;
103104 let log_db_path = filelib:: log:: get_log_db_path ( ) ;
104105
105- // Distribute files over the number of threads
106- let distributed_paths: Vec < Vec < PathBuf > > = utilities:: distribute_paths ( files_paths. clone ( ) ) ;
107-
108- // Run the threads
109- distributed_paths. par_iter ( ) . for_each ( |paths| {
106+ if no_threads {
107+ logger. info ( "start the encryption using the main thread." ) ;
110108 encrypt (
111- paths ,
109+ & files_paths ,
112110 key. clone ( ) ,
113111 is_delete,
114112 log_db_path. clone ( )
115113 ) ;
116- } ) ;
114+ } else {
115+ logger. info ( "start the encryption with the max number of threads." ) ;
116+ // Distribute files over the number of threads
117+ let distributed_paths: Vec < Vec < PathBuf > > = utilities:: distribute_paths ( files_paths. clone ( ) ) ;
118+
119+ // Run the threads
120+ distributed_paths. par_iter ( ) . for_each ( |paths| {
121+ encrypt (
122+ paths,
123+ key. clone ( ) ,
124+ is_delete,
125+ log_db_path. clone ( )
126+ ) ;
127+ } ) ;
128+ }
129+
117130 logger. info ( "directory encrypted successfully." ) ;
118131 displaylib:: key:: display ( key) ;
119132 dblib:: log:: register (
You can’t perform that action at this time.
0 commit comments