From 79e0455b2f9c61f885bc12f48897720c7c5612ea Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Fri, 30 Aug 2002 09:00:16 +0000 Subject: [PATCH] Fix hard/soft links in backup and restore git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@129 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/cats/sql_get.c | 2 +- bacula/src/filed/backup.c | 4 +++- bacula/src/filed/restore.c | 30 ++++++++++++++++++++++-------- bacula/src/findlib/find_one.c | 2 +- bacula/src/version.h | 4 ++-- 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/bacula/src/cats/sql_get.c b/bacula/src/cats/sql_get.c index a32c524cec..2f65ad1bd3 100644 --- a/bacula/src/cats/sql_get.c +++ b/bacula/src/cats/sql_get.c @@ -546,8 +546,8 @@ int db_get_fileset_record(B_DB *mdb, FILESET_DBR *fsr) char ed1[30]; Mmsg1(&mdb->errmsg, _("Got %s FileSets expected only one!\n"), edit_uint64(mdb->num_rows, ed1)); - sql_data_seek(mdb, mdb->num_rows-1); Jmsg(mdb->jcr, M_ERROR, 0, "%s", mdb->errmsg); + sql_data_seek(mdb, mdb->num_rows-1); } if ((row = sql_fetch_row(mdb)) == NULL) { Mmsg1(&mdb->errmsg, _("Error fetching row get_fileset: %s\n"), sql_strerror(mdb)); diff --git a/bacula/src/filed/backup.c b/bacula/src/filed/backup.c index 3e4ddc3946..1d032d22b7 100644 --- a/bacula/src/filed/backup.c +++ b/bacula/src/filed/backup.c @@ -111,6 +111,7 @@ static int save_file(FF_PKT *ff_pkt, void *ijcr) switch (ff_pkt->type) { case FT_LNKSAVED: /* Hard linked, file already saved */ + Dmsg2(130, "FT_LNKSAVED hard link: %s => %s\n", ff_pkt->fname, ff_pkt->link); break; case FT_REGE: Dmsg1(130, "FT_REGE saving: %s\n", ff_pkt->fname); @@ -206,7 +207,8 @@ static int save_file(FF_PKT *ff_pkt, void *ijcr) * For a directory, link is the same as fname, but with trailing * slash. For a linked file, link is the link. */ - if (ff_pkt->type == FT_LNK) { + if (ff_pkt->type == FT_LNK || ff_pkt->type == FT_LNKSAVED) { + Dmsg2(100, "Link %s to %s\n", ff_pkt->fname, ff_pkt->link); stat = bnet_fsend(sd, "%ld %d %s%c%s%c%s%c", jcr->JobFiles, ff_pkt->type, ff_pkt->fname, 0, attribs, 0, ff_pkt->link, 0); } else if (ff_pkt->type == FT_DIR) { diff --git a/bacula/src/filed/restore.c b/bacula/src/filed/restore.c index 46c73a7ced..9ee8f9fd9e 100644 --- a/bacula/src/filed/restore.c +++ b/bacula/src/filed/restore.c @@ -47,7 +47,7 @@ void do_restore(JCR *jcr) BSOCK *sd; POOLMEM *fname; /* original file name */ POOLMEM *ofile; /* output name with possible prefix */ - POOLMEM *lname; /* link name */ + POOLMEM *lname; /* link name with possible prefix */ int32_t stream; uint32_t size; uint32_t VolSessionId, VolSessionTime, file_index; @@ -125,11 +125,11 @@ void do_restore(JCR *jcr) if ((int)sizeof_pool_memory(fname) < sd->msglen) { fname = realloc_pool_memory(fname, sd->msglen + 1); } - if (sizeof_pool_memory(ofile) < sizeof_pool_memory(fname) + wherelen + 1) { - ofile = realloc_pool_memory(ofile, sizeof_pool_memory(fname) + wherelen + 1); + if ((int)sizeof_pool_memory(ofile) < sd->msglen + wherelen + 1) { + ofile = realloc_pool_memory(ofile, sd->msglen + wherelen + 1); } - if ((int)sizeof_pool_memory(lname) < sd->msglen) { - lname = realloc_pool_memory(lname, sd->msglen + 1); + if ((int)sizeof_pool_memory(lname) < sd->msglen + wherelen + 1) { + lname = realloc_pool_memory(lname, sd->msglen + wherelen + 1); } *fname = 0; *lname = 0; @@ -169,14 +169,13 @@ void do_restore(JCR *jcr) *fp = *ap++; /* terminate filename & point to attribs */ /* Skip to Link name */ - if (type == FT_LNK) { + if (type == FT_LNK || type == FT_LNKSAVED) { lp = ap; while (*lp++ != 0) { ; } - strcat(lname, lp); /* "save" link name */ } else { - *lname = 0; + lp = ""; } decode_stat(ap, &statp); @@ -194,6 +193,7 @@ void do_restore(JCR *jcr) */ if (jcr->where[0] == 0 && win32_client) { strcpy(ofile, fname); + strcpy(lname, lp); } else { strcpy(ofile, jcr->where); if (fname[1] == ':') { @@ -203,6 +203,20 @@ void do_restore(JCR *jcr) } else { strcat(ofile, fname); } + /* Fixup link name */ + if (type == FT_LNK || type == FT_LNKSAVED) { + if (lp[0] == '/') { /* if absolute path */ + strcpy(lname, jcr->where); + } + /* ***FIXME**** we shouldn't have links on Windoz */ + if (lp[1] == ':') { + lp[1] = '/'; + strcat(lname, lp); + lp[1] = ':'; + } else { + strcat(lname, lp); + } + } } Dmsg1(30, "Outfile=%s\n", ofile); diff --git a/bacula/src/findlib/find_one.c b/bacula/src/findlib/find_one.c index 8f6c3ae982..937c3dcf28 100755 --- a/bacula/src/findlib/find_one.c +++ b/bacula/src/findlib/find_one.c @@ -137,7 +137,7 @@ find_one_file(FF_PKT *ff_pkt, int handle_file(FF_PKT *ff, void *hpkt), void *pkt * Handle hard linked files * * Maintain a list of hard linked files already backed up. This - * allows us to ensure that the data ofeach file gets backed + * allows us to ensure that the data of each file gets backed * up only once. */ if (ff_pkt->statp.st_nlink > 1 diff --git a/bacula/src/version.h b/bacula/src/version.h index 8f5e2d68ab..432842cad8 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -1,8 +1,8 @@ /* */ #define VERSION "1.25" #define VSTRING "1" -#define DATE "28 August 2002" -#define LSMDATE "29Aug02" +#define DATE "30 August 2002" +#define LSMDATE "30Aug02" /* Debug flags */ #define DEBUG 1 -- 2.39.5