smbclient: Slightly simplify do_mget()
authorVolker Lendecke <vl@samba.org>
Mon, 28 Sep 2020 12:21:24 +0000 (14:21 +0200)
committerJeremy Allison <jra@samba.org>
Wed, 30 Sep 2020 15:58:39 +0000 (15:58 +0000)
Put the prompt query into a separate if-statement, move the "quest"
variable closer to its use

Bug: https://bugzilla.samba.org/show_bug.cgi?id=14517
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/client/client.c

index 6e1d68996d1fee724e525a9d473f863e76a89dc9..d9f4384ef66a3cb7efdefd9e340c5844612e2659 100644 (file)
@@ -1202,7 +1202,6 @@ static NTSTATUS do_mget(struct cli_state *cli_state, struct file_info *finfo,
        TALLOC_CTX *ctx = talloc_tos();
        NTSTATUS status = NT_STATUS_OK;
        char *rname = NULL;
-       char *quest = NULL;
        char *saved_curdir = NULL;
        char *mget_mask = NULL;
        char *new_cd = NULL;
@@ -1214,23 +1213,24 @@ static NTSTATUS do_mget(struct cli_state *cli_state, struct file_info *finfo,
        if (strequal(finfo->name,".") || strequal(finfo->name,".."))
                return NT_STATUS_OK;
 
-       if (finfo->attr & FILE_ATTRIBUTE_DIRECTORY) {
-               if (asprintf(&quest,
-                        "Get directory %s? ",finfo->name) < 0) {
-                       return NT_STATUS_NO_MEMORY;
-               }
-       } else {
-               if (asprintf(&quest,
-                        "Get file %s? ",finfo->name) < 0) {
+       if (prompt) {
+               const char *object = (finfo->attr & FILE_ATTRIBUTE_DIRECTORY) ?
+                       "directory" : "file";
+               char *quest = NULL;
+               bool ok;
+
+               quest = talloc_asprintf(
+                       ctx, "Get %s %s? ", object, finfo->name);
+               if (quest == NULL) {
                        return NT_STATUS_NO_MEMORY;
                }
-       }
 
-       if (prompt && !yesno(quest)) {
-               SAFE_FREE(quest);
-               return NT_STATUS_OK;
+               ok = yesno(quest);
+               TALLOC_FREE(quest);
+               if (!ok) {
+                       return NT_STATUS_OK;
+               }
        }
-       SAFE_FREE(quest);
 
        if (!(finfo->attr & FILE_ATTRIBUTE_DIRECTORY)) {
                rname = talloc_asprintf(ctx,