@@ -274,7 +274,7 @@ get_dup_file_dest_dir(void)
274
274
char * name = file_info [n - 1 ].name ;
275
275
dir = savestring (name , strlen (name ));
276
276
}
277
- } else if (* dir == '~' ) { // Expand tilde
277
+ } else if (* dir == '~' ) { /* Expand tilde */
278
278
char * tmp = tilde_expand (dir );
279
279
if (tmp ) {
280
280
free (dir );
@@ -1643,23 +1643,36 @@ get_rename_dest_filename(char *name, int *status)
1643
1643
1644
1644
/* Get destination filename. */
1645
1645
char * new_name = get_new_filename (name );
1646
- if (!new_name ) {
1646
+ if (!new_name ) { /* The user pressed Ctrl+d */
1647
1647
* status = FUNC_SUCCESS ;
1648
1648
return (char * )NULL ;
1649
1649
}
1650
1650
1651
+ if (* new_name == '~' ) {
1652
+ p = tilde_expand (new_name );
1653
+ if (!p ) {
1654
+ * status = FUNC_FAILURE ;
1655
+ xerror (_ ("m: '%s': Error expanding tilde\n" ), new_name );
1656
+ free (new_name );
1657
+ return (char * )NULL ;
1658
+ } else {
1659
+ free (new_name );
1660
+ new_name = p ;
1661
+ }
1662
+ }
1663
+
1651
1664
return new_name ;
1652
1665
}
1653
1666
1654
1667
1655
1668
/* Run CMD (either cp(1) or mv(1)) via execv().
1656
1669
* skip_force is true (1) when the -f,--force parameter has been provided to
1657
- * either 'c' or 'm' commands: it intructs cp/mv to run non-interactivelly
1670
+ * either 'c' or 'm' commands: it intructs cp/mv to run non-interactively
1658
1671
* (no -i). */
1659
1672
static int
1660
1673
run_cp_mv_cmd (char * * cmd , const int skip_force , const size_t files_num )
1661
1674
{
1662
- if (!cmd )
1675
+ if (!cmd || ! cmd [ 0 ] )
1663
1676
return FUNC_FAILURE ;
1664
1677
1665
1678
char * new_name = (char * )NULL ;
@@ -1714,13 +1727,7 @@ run_cp_mv_cmd(char **cmd, const int skip_force, const size_t files_num)
1714
1727
n ++ ;
1715
1728
} else {
1716
1729
if (new_name ) {
1717
- p = (char * )NULL ;
1718
- if (* new_name == '~' )
1719
- p = tilde_expand (new_name );
1720
- char * q = p ? p : new_name ;
1721
- tcmd [n ] = savestring (q , strlen (q ));
1722
- free (new_name );
1723
- free (p );
1730
+ tcmd [n ] = new_name ;
1724
1731
if (cwd == 0 )
1725
1732
cwd = is_file_in_cwd (tcmd [n ]);
1726
1733
n ++ ;
0 commit comments