From: Christian Ambach Date: Mon, 22 Oct 2018 14:28:21 +0000 (+0200) Subject: s3:utils/smbget add error handling for mkdir() calls X-Git-Tag: samba-4.8.9~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7aba48de14f133b23839dc831beb562005a448a5;p=thirdparty%2Fsamba.git s3:utils/smbget add error handling for mkdir() calls Signed-off-by: Christian Ambach Reviewed-by: Andreas Schneider (cherry picked from commit b89732c31be350828110fe46f2c655f77cb488f3) --- diff --git a/source3/script/tests/test_smbget.sh b/source3/script/tests/test_smbget.sh index 05925f33a01..3f0aac53ad3 100755 --- a/source3/script/tests/test_smbget.sh +++ b/source3/script/tests/test_smbget.sh @@ -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` diff --git a/source3/utils/smbget.c b/source3/utils/smbget.c index 4653c6894e0..ca4bf310466 100644 --- a/source3/utils/smbget.c +++ b/source3/utils/smbget.c @@ -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);