From a20124821838206c249fd19fc7ec1431ddfb8b53 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 4 Jul 2010 11:32:50 +0200 Subject: [PATCH] s3: Fix bug 7338, smbget skips leading slash when using a custom outputfile --- source3/utils/smbget.c | 21 +++++++++++++++------ 1 files changed, 15 insertions(+), 6 deletions(-) diff --git a/source3/utils/smbget.c b/source3/utils/smbget.c index b7d56cd..b5f6b1f 100644 --- a/source3/utils/smbget.c +++ b/source3/utils/smbget.c @@ -49,7 +49,8 @@ static const char *username = NULL, *password = NULL, *workgroup = NULL; static int nonprompt = 0, quiet = 0, dots = 0, keep_permissions = 0, verbose = 0, send_stdout = 0; static int blocksize = SMB_DEFAULT_BLOCKSIZE; -static int smb_download_file(const char *base, const char *name, int recursive, int resume, char *outfile); +static int smb_download_file(const char *base, const char *name, int recursive, + int resume, int toplevel, char *outfile); static int get_num_cols(void) { @@ -129,7 +130,10 @@ static int smb_download_dir(const char *base, const char *name, int resume) /* List files in directory and call smb_download_file on them */ dirhandle = smbc_opendir(path); if(dirhandle < 1) { - if(errno == ENOTDIR) return smb_download_file(base, name, 1, resume, NULL); + if (errno == ENOTDIR) { + return smb_download_file(base, name, 1, resume, + 0, NULL); + } fprintf(stderr, "Can't open directory %s: %s\n", path, strerror(errno)); return 0; } @@ -159,7 +163,7 @@ static int smb_download_dir(const char *base, const char *name, int resume) break; case SMBC_FILE: - smb_download_file(base, newname, 1, resume, NULL); + smb_download_file(base, newname, 1, resume, 0, NULL); break; case SMBC_FILE_SHARE: @@ -258,7 +262,9 @@ static void print_progress(const char *name, time_t start, time_t now, off_t sta free(filename); free(status); } -static int smb_download_file(const char *base, const char *name, int recursive, int resume, char *outfile) { +static int smb_download_file(const char *base, const char *name, int recursive, + int resume, int toplevel, char *outfile) +{ int remotehandle, localhandle; time_t start_time = time(NULL); const char *newpath; @@ -316,7 +322,9 @@ static int smb_download_file(const char *base, const char *name, int recursive, if(newpath)newpath++; else newpath = base; } else newpath = name; - if(newpath[0] == '/')newpath++; + if (!toplevel && (newpath[0] == '/')) { + newpath++; + } /* Open local file according to the mode */ if(update) { @@ -652,7 +660,8 @@ int main(int argc, const char **argv) while ( (file = poptGetArg(pc)) ) { if (!recursive) - return smb_download_file(file, "", recursive, resume, outputfile); + return smb_download_file(file, "", recursive, resume, + 1, outputfile); else return smb_download_dir(file, "", resume); } -- 1.6.5.7