s3:utils/smbget add error handling for mkdir() calls
authorChristian Ambach <ambi@samba.org>
Mon, 22 Oct 2018 14:28:21 +0000 (16:28 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Fri, 26 Oct 2018 04:59:09 +0000 (06:59 +0200)
Signed-off-by: Christian Ambach <ambi@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
source3/script/tests/test_smbget.sh
source3/utils/smbget.c

index 05925f33a01ac259dfcf7fcd13e867a504d0b2ef..3f0aac53ad34d8b6e1c9efc2ca6e0c2d762e5450 100755 (executable)
@@ -134,6 +134,27 @@ test_recursive_U()
        return 0
 }
 
+test_recursive_existing_dir()
+{
+       clear_download_area
+       mkdir dir1
+       $SMBGET -v -R -U$USERNAME%$PASSWORD smb://$SERVER_IP/smbget/
+       if [ $? -ne 0 ]; then
+               echo 'ERROR: RC does not match, expected: 0'
+               return 1
+       fi
+
+       cmp --silent $WORKDIR/testfile ./testfile && \
+       cmp --silent $WORKDIR/dir1/testfile1 ./dir1/testfile1 && \
+       cmp --silent $WORKDIR/dir2/testfile2 ./dir2/testfile2
+       if [ $? -ne 0 ]; then
+               echo 'ERROR: file content does not match'
+               return 1
+       fi
+
+       return 0
+}
+
 test_resume()
 {
        clear_download_area
@@ -222,6 +243,9 @@ testit "download single file with rcfile" test_singlefile_rcfile \
 testit "recursive download" test_recursive_U \
        || failed=`expr $failed + 1`
 
+testit "recursive download (existing target dir)" test_recursive_existing_dir \
+       || failed=`expr $failed + 1`
+
 testit "resume download" test_resume \
        || failed=`expr $failed + 1`
 
index 4653c6894e0049898c093743263b27176b674294..ca4bf310466225f1ce63ebc0cba4fa00e70ee828 100644 (file)
@@ -190,7 +190,15 @@ static bool smb_download_dir(const char *base, const char *name, int resume)
        while (*relname == '/') {
                relname++;
        }
-       mkdir(relname, 0755);
+
+       if (strlen(relname) > 0) {
+               int rc = mkdir(relname, 0755);
+               if (rc == -1 && errno != EEXIST) {
+                       fprintf(stderr, "Can't create directory %s: %s\n",
+                               relname, strerror(errno));
+                       return false;
+               }
+       }
 
        tmpname = SMB_STRDUP(name);