@@ -12,14 +12,14 @@ use nix::errno::Errno;
1212use nix:: fcntl:: { OFlag , open} ;
1313#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
1414use nix:: sys:: stat:: Mode ;
15+ use std:: collections:: HashMap ;
1516use std:: path:: Path ;
1617use uucore:: display:: Quotable ;
1718#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
1819use uucore:: error:: FromIo ;
1920use uucore:: error:: { UResult , USimpleError } ;
2021use uucore:: format_usage;
21-
22- use uucore:: locale:: get_message;
22+ use uucore:: locale:: { get_message, get_message_with_args} ;
2323
2424pub mod options {
2525 pub static FILE_SYSTEM : & str = "file-system" ;
@@ -67,6 +67,7 @@ mod platform {
6767 use std:: os:: windows:: prelude:: * ;
6868 use std:: path:: Path ;
6969 use uucore:: error:: { UResult , USimpleError } ;
70+ use uucore:: locale:: get_message;
7071 use uucore:: wide:: { FromWide , ToWide } ;
7172 use windows_sys:: Win32 :: Foundation :: {
7273 ERROR_NO_MORE_FILES , GetLastError , HANDLE , INVALID_HANDLE_VALUE , MAX_PATH ,
@@ -92,15 +93,15 @@ mod platform {
9293 if unsafe { FlushFileBuffers ( file. as_raw_handle ( ) as HANDLE ) } == 0 {
9394 Err ( USimpleError :: new (
9495 get_last_error ( ) as i32 ,
95- "failed to flush file buffer",
96+ get_message ( "sync-error- flush- file- buffer") ,
9697 ) )
9798 } else {
9899 Ok ( ( ) )
99100 }
100101 }
101102 Err ( e) => Err ( USimpleError :: new (
102103 e. raw_os_error ( ) . unwrap_or ( 1 ) ,
103- "failed to create volume handle",
104+ get_message ( "sync-error- create- volume- handle") ,
104105 ) ) ,
105106 }
106107 } else {
@@ -115,7 +116,7 @@ mod platform {
115116 if handle == INVALID_HANDLE_VALUE {
116117 return Err ( USimpleError :: new (
117118 get_last_error ( ) as i32 ,
118- "failed to find first volume",
119+ get_message ( "sync-error- find- first- volume") ,
119120 ) ) ;
120121 }
121122 Ok ( ( String :: from_wide_null ( & name) , handle) )
@@ -137,7 +138,10 @@ mod platform {
137138 unsafe { FindVolumeClose ( next_volume_handle) } ;
138139 Ok ( volumes)
139140 }
140- err => Err ( USimpleError :: new ( err as i32 , "failed to find next volume" ) ) ,
141+ err => Err ( USimpleError :: new (
142+ err as i32 ,
143+ get_message ( "sync-error-find-next-volume" ) ,
144+ ) ) ,
141145 } ;
142146 } else {
143147 volumes. push ( String :: from_wide_null ( & name) ) ;
@@ -172,14 +176,16 @@ mod platform {
172176#[ uucore:: main]
173177pub fn uumain ( args : impl uucore:: Args ) -> UResult < ( ) > {
174178 let matches = uu_app ( ) . try_get_matches_from ( args) ?;
175-
176179 let files: Vec < String > = matches
177180 . get_many :: < String > ( ARG_FILES )
178181 . map ( |v| v. map ( ToString :: to_string) . collect ( ) )
179182 . unwrap_or_default ( ) ;
180183
181184 if matches. get_flag ( options:: DATA ) && files. is_empty ( ) {
182- return Err ( USimpleError :: new ( 1 , "--data needs at least one argument" ) ) ;
185+ return Err ( USimpleError :: new (
186+ 1 ,
187+ get_message ( "sync-error-data-needs-argument" ) ,
188+ ) ) ;
183189 }
184190
185191 for f in & files {
@@ -189,17 +195,24 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
189195 let path = Path :: new ( & f) ;
190196 if let Err ( e) = open ( path, OFlag :: O_NONBLOCK , Mode :: empty ( ) ) {
191197 if e != Errno :: EACCES || ( e == Errno :: EACCES && path. is_dir ( ) ) {
192- e. map_err_context ( || format ! ( "error opening {}" , f. quote( ) ) ) ?;
198+ e. map_err_context ( || {
199+ get_message_with_args (
200+ "sync-error-opening-file" ,
201+ HashMap :: from ( [ ( "file" . to_string ( ) , f. quote ( ) . to_string ( ) ) ] ) ,
202+ )
203+ } ) ?;
193204 }
194205 }
195206 }
196-
197207 #[ cfg( not( any( target_os = "linux" , target_os = "android" ) ) ) ]
198208 {
199209 if !Path :: new ( & f) . exists ( ) {
200210 return Err ( USimpleError :: new (
201211 1 ,
202- format ! ( "error opening {}: No such file or directory" , f. quote( ) ) ,
212+ get_message_with_args (
213+ "sync-error-no-such-file" ,
214+ HashMap :: from ( [ ( "file" . to_string ( ) , f. quote ( ) . to_string ( ) ) ] ) ,
215+ ) ,
203216 ) ) ;
204217 }
205218 }
@@ -229,15 +242,15 @@ pub fn uu_app() -> Command {
229242 . short ( 'f' )
230243 . long ( options:: FILE_SYSTEM )
231244 . conflicts_with ( options:: DATA )
232- . help ( "sync the file systems that contain the files (Linux and Windows only)" )
245+ . help ( get_message ( "sync-help- file-system" ) )
233246 . action ( ArgAction :: SetTrue ) ,
234247 )
235248 . arg (
236249 Arg :: new ( options:: DATA )
237250 . short ( 'd' )
238251 . long ( options:: DATA )
239252 . conflicts_with ( options:: FILE_SYSTEM )
240- . help ( "sync only file data, no unneeded metadata (Linux only)" )
253+ . help ( get_message ( "sync-help- data" ) )
241254 . action ( ArgAction :: SetTrue ) ,
242255 )
243256 . arg (
0 commit comments