smbclient: add -f option to rename command
authorUri Simchoni <uri@samba.org>
Tue, 21 Mar 2017 21:26:05 +0000 (23:26 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 28 Mar 2017 15:45:19 +0000 (17:45 +0200)
This option causes the rename to request that the
destination file / directory be replaced if it exists.

Supported only in SMB2 and higher protocol.

Signed-off-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/client/client.c

index 78945f92c2b3715d95ae062f7a6cf42ec7cdca32..d2ebea0ad39995bd2bc12deaac4c242af80991c8 100644 (file)
@@ -3833,10 +3833,11 @@ static int cmd_rename(void)
        char *targetsrc;
        char *targetdest;
         NTSTATUS status;
+       bool replace = false;
 
        if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL) ||
            !next_token_talloc(ctx, &cmd_ptr,&buf2,NULL)) {
-               d_printf("rename <src> <dest>\n");
+               d_printf("rename <src> <dest> [-f]\n");
                return 1;
        }
 
@@ -3856,6 +3857,11 @@ static int cmd_rename(void)
                return 1;
        }
 
+       if (next_token_talloc(ctx, &cmd_ptr, &buf, NULL) &&
+           strcsequal(buf, "-f")) {
+               replace = true;
+       }
+
        status = cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli,
                                  &targetsrc);
        if (!NT_STATUS_IS_OK(status)) {
@@ -3870,7 +3876,7 @@ static int cmd_rename(void)
                return 1;
        }
 
-       status = cli_rename(targetcli, targetsrc, targetdest, false);
+       status = cli_rename(targetcli, targetsrc, targetdest, replace);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("%s renaming files %s -> %s \n",
                        nt_errstr(status),