uint32_t record_file_index;
struct stat statp;
int extract = FALSE;
- int ofd = -1;
+ BFILE bfd;
int type, stat;
uint32_t total = 0; /* Job total but only 32 bits for debug */
char *wbuf; /* write buffer */
wherelen = strlen(jcr->where);
+ binit(&bfd);
sd = jcr->store_bsock;
- jcr->JobStatus = JS_Running;
+ set_jcr_job_status(jcr, JS_Running);
if (!bnet_set_buffer_size(sd, MAX_NETWORK_BUFFER_SIZE, BNET_SETBUF_READ)) {
+ set_jcr_job_status(jcr, JS_ErrorTerminated);
return;
}
jcr->buf_size = sd->msglen;
* 2. Stream data
* a. Attributes (Unix or Win32)
* or b. File data for the file
- * or c. Possibly MD5 record
+ * or c. Possibly MD5 or SHA1 record
* 3. Repeat step 1
*/
- while (bnet_recv(sd) >= 0 && !job_cancelled(jcr)) {
+ while (bnet_recv(sd) >= 0 && !job_canceled(jcr)) {
/*
* First we expect a Stream Record Header
*/
/* File Attributes stream */
if (stream == STREAM_UNIX_ATTRIBUTES || stream == STREAM_WIN32_ATTRIBUTES) {
char *ap, *lp, *fp, *apex;
+ uint32_t LinkFI;
Dmsg1(30, "Stream=Unix Attributes. extract=%d\n", extract);
/* If extracting, it was from previous stream, so
* close the output file.
*/
if (extract) {
- if (ofd < 0) {
- Emsg0(M_ERROR, 0, _("Logic error output file should be open\n"));
+ if (!is_bopen(&bfd)) {
+ Jmsg0(jcr, M_ERROR, 0, _("Logic error output file should be open\n"));
}
set_attributes(jcr, fname, ofile, lname, type, stream,
- &statp, attribsEx, &ofd);
+ &statp, attribsEx, &bfd);
extract = FALSE;
Dmsg0(30, "Stop extracting.\n");
}
Dmsg3(200, "File %s\nattrib=%s\nattribsEx=%s\n", fname, ap, attribsEx);
- decode_stat(ap, &statp);
+ decode_stat(ap, &statp, &LinkFI);
/*
* Prepend the where directory so that the
* files are put where the user wants.
/* Ensure where is terminated with a slash */
if (jcr->where[wherelen-1] != '/' && fn[0] != '/') {
strcat(ofile, "/");
- }
+ }
strcat(ofile, fn); /* copy rest of name */
- /* Fixup link name */
- if (type == FT_LNK || type == FT_LNKSAVED) {
- if (lp[0] == '/') { /* if absolute path */
+ /*
+ * Fixup link name -- if it is an absolute path
+ */
+ if (type == FT_LNKSAVED || type == FT_LNK) {
+ int add_link;
+ /* Always add prefix to hard links (FT_LNKSAVED) and
+ * on user request to soft links
+ */
+ if (lp[0] == '/' &&
+ (type == FT_LNKSAVED || jcr->prefix_links)) {
strcpy(lname, jcr->where);
- }
+ add_link = 1;
+ } else {
+ lname[0] = 0;
+ add_link = 0;
+ }
if (win32_client && lp[1] == ':') {
- strcat(lname, lp+2); /* copy rest of name */
+ fn = lp+2; /* skip over drive: */
} else {
- strcat(lname, lp); /* On Unix systems we take everything */
+ fn = lp; /* take whole name */
}
+ /* Ensure where is terminated with a slash */
+ if (add_link && jcr->where[wherelen-1] != '/' && fn[0] != '/') {
+ strcat(lname, "/");
+ }
+ strcat(lname, fn); /* copy rest of link */
}
}
extract = FALSE;
stat = create_file(jcr, fname, ofile, lname, type,
- stream, &statp, attribsEx, &ofd, jcr->replace);
+ stream, &statp, attribsEx, &bfd, jcr->replace);
switch (stat) {
case CF_ERROR:
case CF_SKIP:
P(jcr->mutex);
pm_strcpy(&jcr->last_fname, ofile);
V(jcr->mutex);
- /* Fall-through wanted */
+ jcr->JobFiles++;
+ fileAddr = 0;
+ print_ls_output(jcr, ofile, lname, type, &statp);
+ /* Set attributes after file extracted */
+ break;
case CF_CREATED:
jcr->JobFiles++;
fileAddr = 0;
print_ls_output(jcr, ofile, lname, type, &statp);
+ /* set attributes now because file will not be extracted */
+ set_attributes(jcr, fname, ofile, lname, type, stream,
+ &statp, attribsEx, &bfd);
break;
}
unser_uint64(faddr);
if (fileAddr != faddr) {
fileAddr = faddr;
- if (lseek(ofd, (off_t)fileAddr, SEEK_SET) < 0) {
+ if (blseek(&bfd, (off_t)fileAddr, SEEK_SET) < 0) {
Jmsg3(jcr, M_ERROR, 0, _("Seek to %s error on %s: ERR=%s\n"),
edit_uint64(fileAddr, ec1), ofile, strerror(errno));
goto bail_out;
wsize = sd->msglen;
}
Dmsg2(30, "Write %u bytes, total before write=%u\n", wsize, total);
- if ((uint32_t)write(ofd, wbuf, wsize) != wsize) {
+ if ((uint32_t)bwrite(&bfd, wbuf, wsize) != wsize) {
Dmsg0(0, "===Write error===\n");
Jmsg2(jcr, M_ERROR, 0, _("Write error on %s: %s\n"), ofile, strerror(errno));
goto bail_out;
unser_uint64(faddr);
if (fileAddr != faddr) {
fileAddr = faddr;
- if (lseek(ofd, (off_t)fileAddr, SEEK_SET) < 0) {
+ if (blseek(&bfd, (off_t)fileAddr, SEEK_SET) < 0) {
Jmsg3(jcr, M_ERROR, 0, _("Seek to %s error on %s: ERR=%s\n"),
edit_uint64(fileAddr, ec1), ofile, strerror(errno));
goto bail_out;
}
Dmsg2(100, "Write uncompressed %d bytes, total before write=%d\n", compress_len, total);
- if ((uLong)write(ofd, jcr->compress_buf, compress_len) != compress_len) {
+ if ((uLong)bwrite(&bfd, jcr->compress_buf, compress_len) != compress_len) {
Dmsg0(0, "===Write error===\n");
Jmsg2(jcr, M_ERROR, 0, "Write error on %s: %s\n", ofile, strerror(errno));
goto bail_out;
/* If extracting, wierd stream (not 1 or 2), close output file anyway */
} else if (extract) {
Dmsg1(30, "Found wierd stream %d\n", stream);
- if (ofd < 0) {
- Emsg0(M_ERROR, 0, _("Logic error output file should be open\n"));
+ if (!is_bopen(&bfd)) {
+ Jmsg0(jcr, M_ERROR, 0, _("Logic error output file should be open but is not.\n"));
}
set_attributes(jcr, fname, ofile, lname, type, stream,
- &statp, attribsEx, &ofd);
+ &statp, attribsEx, &bfd);
extract = FALSE;
- } else if (stream != STREAM_MD5_SIGNATURE) {
+ } else if (!(stream == STREAM_MD5_SIGNATURE || stream == STREAM_SHA1_SIGNATURE)) {
Dmsg2(0, "None of above!!! stream=%d data=%s\n", stream,sd->msg);
}
}
/* If output file is still open, it was the last one in the
* archive since we just hit an end of file, so close the file.
*/
- if (ofd >= 0) {
+ if (is_bopen(&bfd)) {
set_attributes(jcr, fname, ofile, lname, type, stream,
- &statp, attribsEx, &ofd);
+ &statp, attribsEx, &bfd);
}
- jcr->JobStatus = JS_Terminated;
+ set_jcr_job_status(jcr, JS_Terminated);
goto ok_out;
bail_out:
- jcr->JobStatus = JS_ErrorTerminated;
+ set_jcr_job_status(jcr, JS_ErrorTerminated);
ok_out:
if (jcr->compress_buf) {
free(jcr->compress_buf);
p = encode_time(statp->st_ctime, p);
*p++ = ' ';
*p++ = ' ';
- for (f=fname; *f && (p-buf) < (int)sizeof(buf); )
+ for (f=fname; *f && (p-buf) < (int)sizeof(buf)-10; ) {
*p++ = *f++;
+ }
if (type == FT_LNK) {
*p++ = ' ';
*p++ = '-';
*p++ = '>';
*p++ = ' ';
/* Copy link name */
- for (f=lname; *f && (p-buf) < (int)sizeof(buf); )
+ for (f=lname; *f && (p-buf) < (int)sizeof(buf)-10; ) {
*p++ = *f++;
+ }
}
*p++ = '\n';
*p = 0;
Dmsg0(20, buf);
- Jmsg(jcr, M_INFO, 0, "%s", buf);
+ Jmsg(jcr, M_RESTORED, 0, "%s", buf);
}