33// For the full copyright and license information, please view the LICENSE
44// file that was distributed with this source code.
55
6- // spell-checker:ignore (ToDO) sourcepath targetpath nushell canonicalized
6+ // spell-checker:ignore (ToDO) sourcepath targetpath nushell canonicalized renameat FDCWD ENOTSUP
77
88mod error;
99#[ cfg( unix) ]
@@ -53,6 +53,7 @@ use fs_extra::dir::get_size as dir_get_size;
5353
5454use crate :: error:: MvError ;
5555use uucore:: locale:: { get_message, get_message_with_args} ;
56+ use uucore:: translate;
5657
5758/// Options contains all the possible behaviors and flags for mv.
5859///
@@ -185,25 +186,25 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
185186 if files. len ( ) != 2 {
186187 return Err ( UUsageError :: new (
187188 1 ,
188- get_message ( "mv-error -exchange-needs- two- files") ,
189+ translate ! ( "- -exchange requires exactly two files") ,
189190 ) ) ;
190191 }
191192 if matches. contains_id ( OPT_TARGET_DIRECTORY ) {
192193 return Err ( UUsageError :: new (
193194 1 ,
194- get_message ( "mv-error -exchange- conflicts- with-target-directory") ,
195+ translate ! ( "- -exchange conflicts with - -target-directory") ,
195196 ) ) ;
196197 }
197198 if backup_mode != BackupMode :: None {
198199 return Err ( UUsageError :: new (
199200 1 ,
200- get_message ( "mv-error -exchange- conflicts- with- backup") ,
201+ translate ! ( "- -exchange conflicts with backup options ") ,
201202 ) ) ;
202203 }
203204 if update_mode != UpdateMode :: All {
204205 return Err ( UUsageError :: new (
205206 1 ,
206- get_message ( "mv-error -exchange- conflicts- with- update") ,
207+ translate ! ( "- -exchange conflicts with update options ") ,
207208 ) ) ;
208209 }
209210 }
@@ -331,7 +332,7 @@ pub fn uu_app() -> Command {
331332 . arg (
332333 Arg :: new ( OPT_EXCHANGE )
333334 . long ( OPT_EXCHANGE )
334- . help ( get_message ( "mv-help- exchange") )
335+ . help ( translate ! ( " exchange two files ") )
335336 . action ( ArgAction :: SetTrue ) ,
336337 )
337338}
@@ -358,10 +359,8 @@ fn exchange_files(path1: &Path, path2: &Path, opts: &Options) -> UResult<()> {
358359 use std:: os:: unix:: ffi:: OsStrExt ;
359360
360361 // Convert paths to C strings
361- let c_path1 = CString :: new ( path1. as_os_str ( ) . as_bytes ( ) )
362- . map_err ( |e| USimpleError :: new ( 1 , format ! ( "Invalid path {}: {e}" , path1. display( ) ) ) ) ?;
363- let c_path2 = CString :: new ( path2. as_os_str ( ) . as_bytes ( ) )
364- . map_err ( |e| USimpleError :: new ( 1 , format ! ( "Invalid path {}: {e}" , path2. display( ) ) ) ) ?;
362+ let c_path1 = CString :: new ( path1. as_os_str ( ) . as_bytes ( ) ) . unwrap ( ) ;
363+ let c_path2 = CString :: new ( path2. as_os_str ( ) . as_bytes ( ) ) . unwrap ( ) ;
365364
366365 // RENAME_EXCHANGE flag for renameat2
367366 const RENAME_EXCHANGE : libc:: c_int = 2 ;
@@ -380,23 +379,23 @@ fn exchange_files(path1: &Path, path2: &Path, opts: &Options) -> UResult<()> {
380379
381380 if result == 0 {
382381 if opts. verbose {
383- println ! ( "{} <-> {} " , path1. display( ) , path2. display( ) ) ;
382+ println ! ( "exchanged '{}' <-> '{}' " , path1. display( ) , path2. display( ) ) ;
384383 }
385384 Ok ( ( ) )
386385 } else {
387386 let errno = unsafe { * libc:: __errno_location ( ) } ;
388387 match errno {
389388 libc:: ENOTSUP | libc:: EINVAL => Err ( USimpleError :: new (
390389 1 ,
391- get_message ( "mv-error -exchange- not- supported") ,
390+ translate ! ( "- -exchange is not supported on this filesystem ") ,
392391 ) ) ,
393392 libc:: ENOENT => {
394393 let missing_path = if path1. exists ( ) { path2 } else { path1 } ;
395394 Err ( MvError :: NoSuchFile ( missing_path. display ( ) . to_string ( ) ) . into ( ) )
396395 }
397396 libc:: EXDEV => Err ( USimpleError :: new (
398397 1 ,
399- get_message ( "mv-error -exchange-cross-device ") ,
398+ translate ! ( "- -exchange cannot exchange files across different filesystems ") ,
400399 ) ) ,
401400 _ => {
402401 let error_msg = io:: Error :: from_raw_os_error ( errno) ;
@@ -414,7 +413,7 @@ fn exchange_files(path1: &Path, path2: &Path, opts: &Options) -> UResult<()> {
414413fn exchange_files ( _path1 : & Path , _path2 : & Path , _opts : & Options ) -> UResult < ( ) > {
415414 Err ( USimpleError :: new (
416415 1 ,
417- get_message ( "mv-error -exchange- not- supported") ,
416+ translate ! ( "- -exchange is not supported on this system ") ,
418417 ) )
419418}
420419
@@ -648,7 +647,7 @@ pub fn mv(files: &[OsString], opts: &Options) -> UResult<()> {
648647 if paths. len ( ) != 2 {
649648 return Err ( USimpleError :: new (
650649 1 ,
651- get_message ( "mv-error -exchange-needs- two- files") ,
650+ translate ! ( "- -exchange requires exactly two files") ,
652651 ) ) ;
653652 }
654653 return exchange_files ( & paths[ 0 ] , & paths[ 1 ] , opts) ;
0 commit comments