@@ -20,7 +20,8 @@ use uucore::parser::parse_size::parse_size_u64;
20
20
use uucore:: parser:: shortcut_value_parser:: ShortcutValueParser ;
21
21
use uucore:: { format_usage, show_error, show_if_err} ;
22
22
23
- use uucore:: locale:: get_message;
23
+ use std:: collections:: HashMap ;
24
+ use uucore:: locale:: { get_message, get_message_with_args} ;
24
25
25
26
pub mod options {
26
27
pub const FORCE : & str = "force" ;
@@ -242,7 +243,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
242
243
let matches = uu_app ( ) . try_get_matches_from ( args) ?;
243
244
244
245
if !matches. contains_id ( options:: FILE ) {
245
- return Err ( UUsageError :: new ( 1 , "missing file operand" ) ) ;
246
+ return Err ( UUsageError :: new (
247
+ 1 ,
248
+ get_message ( "shred-missing-file-operand" ) ,
249
+ ) ) ;
246
250
}
247
251
248
252
let iterations = match matches. get_one :: < String > ( options:: ITERATIONS ) {
@@ -251,7 +255,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
251
255
Err ( _) => {
252
256
return Err ( USimpleError :: new (
253
257
1 ,
254
- format ! ( "invalid number of passes: {}" , s. quote( ) ) ,
258
+ get_message_with_args (
259
+ "shred-invalid-number-of-passes" ,
260
+ HashMap :: from ( [ ( "passes" . to_string ( ) , s. quote ( ) . to_string ( ) ) ] ) ,
261
+ ) ,
255
262
) ) ;
256
263
}
257
264
} ,
@@ -262,7 +269,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
262
269
Some ( filepath) => RandomSource :: Read ( File :: open ( filepath) . map_err ( |_| {
263
270
USimpleError :: new (
264
271
1 ,
265
- format ! ( "cannot open random source: {}" , filepath. quote( ) ) ,
272
+ get_message_with_args (
273
+ "shred-cannot-open-random-source" ,
274
+ HashMap :: from ( [ ( "source" . to_string ( ) , filepath. quote ( ) . to_string ( ) ) ] ) ,
275
+ ) ,
266
276
)
267
277
} ) ?) ,
268
278
None => RandomSource :: System ,
@@ -321,14 +331,14 @@ pub fn uu_app() -> Command {
321
331
Arg :: new ( options:: FORCE )
322
332
. long ( options:: FORCE )
323
333
. short ( 'f' )
324
- . help ( "change permissions to allow writing if necessary" )
334
+ . help ( get_message ( "shred-force-help" ) )
325
335
. action ( ArgAction :: SetTrue ) ,
326
336
)
327
337
. arg (
328
338
Arg :: new ( options:: ITERATIONS )
329
339
. long ( options:: ITERATIONS )
330
340
. short ( 'n' )
331
- . help ( "overwrite N times instead of the default (3)" )
341
+ . help ( get_message ( "shred-iterations-help" ) )
332
342
. value_name ( "NUMBER" )
333
343
. default_value ( "3" ) ,
334
344
)
@@ -337,12 +347,12 @@ pub fn uu_app() -> Command {
337
347
. long ( options:: SIZE )
338
348
. short ( 's' )
339
349
. value_name ( "N" )
340
- . help ( "shred this many bytes (suffixes like K, M, G accepted)" ) ,
350
+ . help ( get_message ( "shred-size-help" ) ) ,
341
351
)
342
352
. arg (
343
353
Arg :: new ( options:: WIPESYNC )
344
354
. short ( 'u' )
345
- . help ( " deallocate and remove file after overwriting" )
355
+ . help ( get_message ( "shred- deallocate-help" ) )
346
356
. action ( ArgAction :: SetTrue ) ,
347
357
)
348
358
. arg (
@@ -357,37 +367,34 @@ pub fn uu_app() -> Command {
357
367
. num_args ( 0 ..=1 )
358
368
. require_equals ( true )
359
369
. default_missing_value ( options:: remove:: WIPESYNC )
360
- . help ( "like -u but give control on HOW to delete; See below" )
370
+ . help ( get_message ( "shred-remove-help" ) )
361
371
. action ( ArgAction :: Set ) ,
362
372
)
363
373
. arg (
364
374
Arg :: new ( options:: VERBOSE )
365
375
. long ( options:: VERBOSE )
366
376
. short ( 'v' )
367
- . help ( "show progress" )
377
+ . help ( get_message ( "shred-verbose-help" ) )
368
378
. action ( ArgAction :: SetTrue ) ,
369
379
)
370
380
. arg (
371
381
Arg :: new ( options:: EXACT )
372
382
. long ( options:: EXACT )
373
383
. short ( 'x' )
374
- . help (
375
- "do not round file sizes up to the next full block;\n \
376
- this is the default for non-regular files",
377
- )
384
+ . help ( get_message ( "shred-exact-help" ) )
378
385
. action ( ArgAction :: SetTrue ) ,
379
386
)
380
387
. arg (
381
388
Arg :: new ( options:: ZERO )
382
389
. long ( options:: ZERO )
383
390
. short ( 'z' )
384
- . help ( "add a final overwrite with zeros to hide shredding" )
391
+ . help ( get_message ( "shred-zero-help" ) )
385
392
. action ( ArgAction :: SetTrue ) ,
386
393
)
387
394
. arg (
388
395
Arg :: new ( options:: RANDOM_SOURCE )
389
396
. long ( options:: RANDOM_SOURCE )
390
- . help ( "take random bytes from FILE" )
397
+ . help ( get_message ( "shred- random-source-help" ) )
391
398
. value_hint ( clap:: ValueHint :: FilePath )
392
399
. action ( ArgAction :: Set ) ,
393
400
)
@@ -405,7 +412,13 @@ fn get_size(size_str_opt: Option<String>) -> Option<u64> {
405
412
. and_then ( |size| parse_size_u64 ( size. as_str ( ) ) . ok ( ) )
406
413
. or_else ( || {
407
414
if let Some ( size) = size_str_opt {
408
- show_error ! ( "invalid file size: {}" , size. quote( ) ) ;
415
+ show_error ! (
416
+ "{}" ,
417
+ get_message_with_args(
418
+ "shred-invalid-file-size" ,
419
+ HashMap :: from( [ ( "size" . to_string( ) , size. quote( ) . to_string( ) ) ] )
420
+ )
421
+ ) ;
409
422
// TODO: replace with our error management
410
423
std:: process:: exit ( 1 ) ;
411
424
}
@@ -439,13 +452,19 @@ fn wipe_file(
439
452
if !path. exists ( ) {
440
453
return Err ( USimpleError :: new (
441
454
1 ,
442
- format ! ( "{}: No such file or directory" , path. maybe_quote( ) ) ,
455
+ get_message_with_args (
456
+ "shred-no-such-file-or-directory" ,
457
+ HashMap :: from ( [ ( "file" . to_string ( ) , path. maybe_quote ( ) . to_string ( ) ) ] ) ,
458
+ ) ,
443
459
) ) ;
444
460
}
445
461
if !path. is_file ( ) {
446
462
return Err ( USimpleError :: new (
447
463
1 ,
448
- format ! ( "{}: Not a file" , path. maybe_quote( ) ) ,
464
+ get_message_with_args (
465
+ "shred-not-a-file" ,
466
+ HashMap :: from ( [ ( "file" . to_string ( ) , path. maybe_quote ( ) . to_string ( ) ) ] ) ,
467
+ ) ,
449
468
) ) ;
450
469
}
451
470
@@ -528,10 +547,14 @@ fn wipe_file(
528
547
for ( i, pass_type) in pass_sequence. into_iter ( ) . enumerate ( ) {
529
548
if verbose {
530
549
let pass_name = pass_name ( & pass_type) ;
550
+ let msg = get_message_with_args (
551
+ "shred-pass-progress" ,
552
+ HashMap :: from ( [ ( "file" . to_string ( ) , path. maybe_quote ( ) . to_string ( ) ) ] ) ,
553
+ ) ;
531
554
show_error ! (
532
- "{}: pass {}/{total_passes} ({pass_name})..." ,
533
- path . maybe_quote ( ) ,
534
- i + 1 ,
555
+ "{} {}/{total_passes} ({pass_name})..." ,
556
+ msg ,
557
+ ( i + 1 ) . to_string ( )
535
558
) ;
536
559
}
537
560
// size is an optional argument for exactly how many bytes we want to shred
@@ -614,11 +637,14 @@ fn wipe_name(orig_path: &Path, verbose: bool, remove_method: RemoveMethod) -> Op
614
637
match fs:: rename ( & last_path, & new_path) {
615
638
Ok ( ( ) ) => {
616
639
if verbose {
617
- show_error ! (
618
- "{}: renamed to {}" ,
619
- last_path. maybe_quote( ) ,
620
- new_path. display( )
640
+ let msg = get_message_with_args (
641
+ "shred-renamed-to" ,
642
+ HashMap :: from ( [
643
+ ( "file" . to_string ( ) , last_path. maybe_quote ( ) . to_string ( ) ) ,
644
+ ( "new_name" . to_string ( ) , new_path. display ( ) . to_string ( ) ) ,
645
+ ] ) ,
621
646
) ;
647
+ show_error ! ( "{}" , msg) ;
622
648
}
623
649
624
650
if remove_method == RemoveMethod :: WipeSync {
@@ -634,11 +660,15 @@ fn wipe_name(orig_path: &Path, verbose: bool, remove_method: RemoveMethod) -> Op
634
660
break ;
635
661
}
636
662
Err ( e) => {
637
- show_error ! (
638
- "{}: Couldn't rename to {}: {e}" ,
639
- last_path. maybe_quote( ) ,
640
- new_path. quote( ) ,
663
+ let msg = get_message_with_args (
664
+ "shred-couldnt-rename" ,
665
+ HashMap :: from ( [
666
+ ( "file" . to_string ( ) , last_path. maybe_quote ( ) . to_string ( ) ) ,
667
+ ( "new_name" . to_string ( ) , new_path. quote ( ) . to_string ( ) ) ,
668
+ ( "error" . to_string ( ) , e. to_string ( ) ) ,
669
+ ] ) ,
641
670
) ;
671
+ show_error ! ( "{}" , msg) ;
642
672
// TODO: replace with our error management
643
673
std:: process:: exit ( 1 ) ;
644
674
}
@@ -656,7 +686,13 @@ fn do_remove(
656
686
remove_method : RemoveMethod ,
657
687
) -> Result < ( ) , io:: Error > {
658
688
if verbose {
659
- show_error ! ( "{}: removing" , orig_filename. maybe_quote( ) ) ;
689
+ show_error ! (
690
+ "{}" ,
691
+ get_message_with_args(
692
+ "shred-removing" ,
693
+ HashMap :: from( [ ( "file" . to_string( ) , orig_filename. maybe_quote( ) . to_string( ) ) ] )
694
+ )
695
+ ) ;
660
696
}
661
697
662
698
let remove_path = if remove_method == RemoveMethod :: Unlink {
@@ -670,7 +706,13 @@ fn do_remove(
670
706
}
671
707
672
708
if verbose {
673
- show_error ! ( "{}: removed" , orig_filename. maybe_quote( ) ) ;
709
+ show_error ! (
710
+ "{}" ,
711
+ get_message_with_args(
712
+ "shred-removed" ,
713
+ HashMap :: from( [ ( "file" . to_string( ) , orig_filename. maybe_quote( ) . to_string( ) ) ] )
714
+ )
715
+ ) ;
674
716
}
675
717
676
718
Ok ( ( ) )
0 commit comments