summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2006-04-20 00:47:46 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 11:16:26 -0500
commit2ebcc2933a12f5df69bf1ea9225ae4989c6208eb (patch)
tree4b5babdd03c5a096d9fa9c09869508b31ac9f7f6 /source3
parentf60111e074eba237ef2ad416bfd3847ce314e773 (diff)
downloadsamba-2ebcc2933a12f5df69bf1ea9225ae4989c6208eb.tar.gz
samba-2ebcc2933a12f5df69bf1ea9225ae4989c6208eb.tar.bz2
samba-2ebcc2933a12f5df69bf1ea9225ae4989c6208eb.zip
r15141: Fix for #3592 inspired by Justin Best <justinb@pdxmission.org>.
Ignore a file in a tar output if the first read fails. Also cope with <2GB read fail. Jeremy. (This used to be commit 1b73e699e11c6e26e9a9123e74190eebd170fc05)
Diffstat (limited to 'source3')
-rw-r--r--source3/client/clitar.c49
1 files changed, 30 insertions, 19 deletions
diff --git a/source3/client/clitar.c b/source3/client/clitar.c
index 306848bc0c..a7bc4bfde3 100644
--- a/source3/client/clitar.c
+++ b/source3/client/clitar.c
@@ -561,15 +561,15 @@ static BOOL ensurepath(char *fname)
return True;
}
-static int padit(char *buf, int bufsize, int padsize)
+static int padit(char *buf, SMB_BIG_UINT bufsize, SMB_BIG_UINT padsize)
{
int berr= 0;
int bytestowrite;
- DEBUG(5, ("Padding with %d zeros\n", padsize));
- memset(buf, 0, bufsize);
+ DEBUG(5, ("Padding with %0.f zeros\n", (double)padsize));
+ memset(buf, 0, (size_t)bufsize);
while( !berr && padsize > 0 ) {
- bytestowrite= MIN(bufsize, padsize);
+ bytestowrite= (int)MIN(bufsize, padsize);
berr = dotarbuf(tarhandle, buf, bytestowrite) != bytestowrite;
padsize -= bytestowrite;
}
@@ -682,12 +682,11 @@ static void do_atar(char *rname,char *lname,file_info *finfo1)
DEBUG(4, ("skipping %s - hidden bit is set\n", finfo.name));
shallitime=0;
} else {
+ BOOL wrote_tar_header = False;
+
DEBUG(3,("getting file %s of size %.0f bytes as a tar file %s",
finfo.name, (double)finfo.size, lname));
- /* write a tar header, don't bother with mode - just set to 100644 */
- writetarheader(tarhandle, rname, finfo.size, finfo.mtime, "100644 \0", ftype);
-
while (nread < finfo.size && !close_done) {
DEBUG(3,("nread=%.0f\n",(double)nread));
@@ -701,6 +700,13 @@ static void do_atar(char *rname,char *lname,file_info *finfo1)
nread += datalen;
+ /* Only if the first read succeeds, write out the tar header. */
+ if (!wrote_tar_header) {
+ /* write a tar header, don't bother with mode - just set to 100644 */
+ writetarheader(tarhandle, rname, finfo.size, finfo.mtime, "100644 \0", ftype);
+ wrote_tar_header = True;
+ }
+
/* if file size has increased since we made file size query, truncate
read so tar header for this file will be correct.
*/
@@ -727,20 +733,25 @@ static void do_atar(char *rname,char *lname,file_info *finfo1)
datalen=0;
}
- /* pad tar file with zero's if we couldn't get entire file */
- if (nread < finfo.size) {
- DEBUG(0, ("Didn't get entire file. size=%.0f, nread=%d\n",
- (double)finfo.size, (int)nread));
- if (padit(data, sizeof(data), finfo.size - nread))
- DEBUG(0,("Error writing tar file - %s\n", strerror(errno)));
- }
+ if (wrote_tar_header) {
+ /* pad tar file with zero's if we couldn't get entire file */
+ if (nread < finfo.size) {
+ DEBUG(0, ("Didn't get entire file. size=%.0f, nread=%d\n",
+ (double)finfo.size, (int)nread));
+ if (padit(data, (SMB_BIG_UINT)sizeof(data), finfo.size - nread))
+ DEBUG(0,("Error writing tar file - %s\n", strerror(errno)));
+ }
- /* round tar file to nearest block */
- if (finfo.size % TBLOCK)
- dozerobuf(tarhandle, TBLOCK - (finfo.size % TBLOCK));
+ /* round tar file to nearest block */
+ if (finfo.size % TBLOCK)
+ dozerobuf(tarhandle, TBLOCK - (finfo.size % TBLOCK));
- ttarf+=finfo.size + TBLOCK - (finfo.size % TBLOCK);
- ntarf++;
+ ttarf+=finfo.size + TBLOCK - (finfo.size % TBLOCK);
+ ntarf++;
+ } else {
+ DEBUG(4, ("skipping %s - initial read failed (file was locked ?)\n", finfo.name));
+ shallitime=0;
+ }
}
cli_close(cli, fnum);