From: Kern Sibbald Date: Sat, 11 Aug 2018 19:20:22 +0000 (+0200) Subject: Permit catalog to contain negative FileIndexes X-Git-Tag: Release-9.2.1~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ac391519c8e4125db0662dea92e7550d95bd9a16;p=thirdparty%2Fbacula.git Permit catalog to contain negative FileIndexes --- diff --git a/bacula/src/cats/bvfs.c b/bacula/src/cats/bvfs.c index afd4fa330..787b1a72b 100644 --- a/bacula/src/cats/bvfs.c +++ b/bacula/src/cats/bvfs.c @@ -439,7 +439,7 @@ static int update_path_hierarchy_cache(JCR *jcr, /* Inserting path records for JobId */ Mmsg(mdb->cmd, "INSERT INTO PathVisibility (PathId, JobId) " "SELECT DISTINCT PathId, JobId " - "FROM (SELECT PathId, JobId FROM File WHERE JobId = %s AND FileIndex <> 0 " + "FROM (SELECT PathId, JobId FROM File WHERE JobId = %s AND FileIndex > 0 " "UNION " "SELECT PathId, BaseFiles.JobId " "FROM BaseFiles JOIN File AS F USING (FileId) " diff --git a/bacula/src/cats/cats.h b/bacula/src/cats/cats.h index a1223bab7..bb102bd60 100644 --- a/bacula/src/cats/cats.h +++ b/bacula/src/cats/cats.h @@ -161,7 +161,7 @@ struct JOB_DBR { int order; /* 0 ASC, 1 DESC */ int limit; /* limit records to display */ faddr_t rec_addr; - uint32_t FileIndex; /* added during Verify */ + int32_t FileIndex; /* added during Verify */ int CorrNbJob; /* used by dbd_get_job_statistics() */ int CorrJobBytes; /* used by dbd_get_job_statistics() */ @@ -208,7 +208,7 @@ struct ATTR_DBR { char *fname; /* full path & filename */ char *link; /* link if any */ char *attr; /* attributes statp */ - uint32_t FileIndex; + int32_t FileIndex; uint32_t Stream; uint32_t FileType; uint32_t DeltaSeq; @@ -230,7 +230,7 @@ struct ROBJECT_DBR { uint32_t object_full_len; uint32_t object_index; int32_t object_compression; - uint32_t FileIndex; + int32_t FileIndex; uint32_t Stream; uint32_t FileType; JobId_t JobId; @@ -241,8 +241,8 @@ struct ROBJECT_DBR { /* File record -- same format as database */ struct FILE_DBR { FileId_t FileId; - uint32_t FileIndex; - uint32_t FileIndex2; + int32_t FileIndex; + int32_t FileIndex2; JobId_t JobId; DBId_t FilenameId; DBId_t PathId; diff --git a/bacula/src/cats/make_mysql_tables.in b/bacula/src/cats/make_mysql_tables.in index db5fc9eba..f41a6345f 100644 --- a/bacula/src/cats/make_mysql_tables.in +++ b/bacula/src/cats/make_mysql_tables.in @@ -60,7 +60,7 @@ CREATE TABLE Path ( -- FileNameId can link to Filename.Name='' for directories CREATE TABLE File ( FileId BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, - FileIndex INTEGER UNSIGNED DEFAULT 0, + FileIndex INTEGER DEFAULT 0, JobId INTEGER UNSIGNED NOT NULL REFERENCES Job, PathId INTEGER UNSIGNED NOT NULL REFERENCES Path, FilenameId INTEGER UNSIGNED NOT NULL REFERENCES Filename, @@ -82,7 +82,7 @@ CREATE TABLE RestoreObject ( ObjectFullLength INTEGER DEFAULT 0, ObjectIndex INTEGER DEFAULT 0, ObjectType INTEGER DEFAULT 0, - FileIndex INTEGER UNSIGNED DEFAULT 0, + FileIndex INTEGER DEFAULT 0, JobId INTEGER UNSIGNED NOT NULL REFERENCES Job, ObjectCompression INTEGER DEFAULT 0, PRIMARY KEY(RestoreObjectId), @@ -365,7 +365,7 @@ CREATE TABLE BaseFiles ( BaseJobId INTEGER UNSIGNED NOT NULL REFERENCES Job, JobId INTEGER UNSIGNED NOT NULL REFERENCES Job, FileId BIGINT UNSIGNED NOT NULL REFERENCES File, - FileIndex INTEGER UNSIGNED, + FileIndex INTEGER DEFAULT 0, PRIMARY KEY(BaseId) ); diff --git a/bacula/src/cats/make_postgresql_tables.in b/bacula/src/cats/make_postgresql_tables.in index 43833c4a9..4196d0745 100644 --- a/bacula/src/cats/make_postgresql_tables.in +++ b/bacula/src/cats/make_postgresql_tables.in @@ -360,7 +360,7 @@ CREATE TABLE basefiles baseid bigserial not null, jobid integer not null, fileid bigint not null, - fileindex integer , + fileindex integer default 0, basejobid integer , primary key (baseid) ); diff --git a/bacula/src/cats/make_sqlite3_tables.in b/bacula/src/cats/make_sqlite3_tables.in index c5f3b09c2..844ae54da 100644 --- a/bacula/src/cats/make_sqlite3_tables.in +++ b/bacula/src/cats/make_sqlite3_tables.in @@ -33,7 +33,7 @@ CREATE INDEX inx2 ON Path (Path); -- FileNameId can link to Filename.Name='' for directories CREATE TABLE File ( FileId INTEGER, - FileIndex INTEGER UNSIGNED NOT NULL, + FileIndex INTEGER DEFAULT 0, JobId INTEGER UNSIGNED REFERENCES Job NOT NULL, PathId INTEGER UNSIGNED REFERENCES Path NOT NULL, FilenameId INTEGER UNSIGNED REFERENCES Filename NOT NULL, @@ -62,7 +62,7 @@ CREATE TABLE RestoreObject ( ObjectFullLength INTEGER DEFAULT 0, ObjectIndex INTEGER DEFAULT 0, ObjectType INTEGER DEFAULT 0, - FileIndex INTEGER UNSIGNED DEFAULT 0, + FileIndex INTEGER DEFAULT 0, ObjectCompression INTEGER DEFAULT 0, JobId INTEGER UNSIGNED REFERENCES Job NOT NULL, PRIMARY KEY(RestoreObjectId) @@ -338,7 +338,7 @@ CREATE TABLE BaseFiles ( BaseJobId INTEGER UNSIGNED REFERENCES Job NOT NULL, JobId INTEGER UNSIGNED REFERENCES Job NOT NULL, FileId INTEGER UNSIGNED REFERENCES File NOT NULL, - FileIndex INTEGER UNSIGNED, + FileIndex INTEGER DEFAULT 0, PRIMARY KEY(BaseId) ); diff --git a/bacula/src/cats/mysql.c b/bacula/src/cats/mysql.c index 5abfa4390..d3a0c46f4 100644 --- a/bacula/src/cats/mysql.c +++ b/bacula/src/cats/mysql.c @@ -754,7 +754,7 @@ bool BDB_MYSQL::sql_batch_insert(JCR *jcr, ATTR_DBR *ar) */ if (mdb->changes == 0) { Mmsg(cmd, "INSERT INTO batch VALUES " - "(%u,%s,'%s','%s','%s','%s',%u)", + "(%d,%s,'%s','%s','%s','%s',%u)", ar->FileIndex, edit_int64(ar->JobId,ed1), mdb->esc_path, mdb->esc_name, ar->attr, digest, ar->DeltaSeq); mdb->changes++; @@ -763,7 +763,7 @@ bool BDB_MYSQL::sql_batch_insert(JCR *jcr, ATTR_DBR *ar) * We use the esc_obj for temporary storage otherwise * we keep on copying data. */ - Mmsg(mdb->esc_obj, ",(%u,%s,'%s','%s','%s','%s',%u)", + Mmsg(mdb->esc_obj, ",(%d,%s,'%s','%s','%s','%s',%u)", ar->FileIndex, edit_int64(ar->JobId,ed1), mdb->esc_path, mdb->esc_name, ar->attr, digest, ar->DeltaSeq); pm_strcat(mdb->cmd, mdb->esc_obj); diff --git a/bacula/src/cats/sql_cmds.c b/bacula/src/cats/sql_cmds.c index 06b23b253..5fe303153 100644 --- a/bacula/src/cats/sql_cmds.c +++ b/bacula/src/cats/sql_cmds.c @@ -1,8 +1,7 @@ /* Bacula(R) - The Network Backup Solution - Copyright (C) 2000-2015 Kern Sibbald - Copyright (C) 2000-2014 Free Software Foundation Europe e.V. + Copyright (C) 2000-2018 Kern Sibbald The original author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. diff --git a/bacula/src/cats/sql_create.c b/bacula/src/cats/sql_create.c index 5f72bacee..578814729 100644 --- a/bacula/src/cats/sql_create.c +++ b/bacula/src/cats/sql_create.c @@ -960,7 +960,7 @@ int BDB::bdb_create_file_record(JCR *jcr, ATTR_DBR *ar) /* Must create it */ Mmsg(cmd, "INSERT INTO File (FileIndex,JobId,PathId,FilenameId," - "LStat,MD5,DeltaSeq) VALUES (%u,%u,%u,%u,'%s','%s',%u)", + "LStat,MD5,DeltaSeq) VALUES (%d,%u,%u,%u,'%s','%s',%u)", ar->FileIndex, ar->JobId, ar->PathId, ar->FilenameId, ar->attr, digest, ar->DeltaSeq); diff --git a/bacula/src/cats/sql_get.c b/bacula/src/cats/sql_get.c index 201017bcd..85c5df549 100644 --- a/bacula/src/cats/sql_get.c +++ b/bacula/src/cats/sql_get.c @@ -1,7 +1,7 @@ /* Bacula(R) - The Network Backup Solution - Copyright (C) 2000-2017 Kern Sibbald + Copyright (C) 2000-2018 Kern Sibbald The original author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -102,7 +102,7 @@ bool BDB::bdb_get_file_record(JCR *jcr, JOB_DBR *jr, FILE_DBR *fdbr) case L_VERIFY_VOLUME_TO_CATALOG: Mmsg(cmd, "SELECT FileId, LStat, MD5 FROM File WHERE File.JobId=%s AND File.PathId=%s AND " -"File.FilenameId=%s AND File.FileIndex=%u", +"File.FilenameId=%s AND File.FileIndex=%d", edit_int64(fdbr->JobId, ed1), edit_int64(fdbr->PathId, ed2), edit_int64(fdbr->FilenameId,ed3), diff --git a/bacula/src/cats/sql_list.c b/bacula/src/cats/sql_list.c index 0090a2549..20ab42f04 100644 --- a/bacula/src/cats/sql_list.c +++ b/bacula/src/cats/sql_list.c @@ -570,10 +570,10 @@ void BDB::bdb_list_files_for_job(JCR *jcr, JobId_t jobid, int deleted, DB_LIST_H switch (deleted) { case 0: /* Show only actual files */ - opt = " AND FileIndex <> 0 "; + opt = " AND FileIndex > 0 "; break; case 1: /* Show only deleted files */ - opt = " AND FileIndex = 0 "; + opt = " AND FileIndex <= 0 "; break; default: /* Show everything */ opt = ""; diff --git a/bacula/src/cats/update_mysql_tables.in b/bacula/src/cats/update_mysql_tables.in index 81e9163b6..2dbc3434a 100644 --- a/bacula/src/cats/update_mysql_tables.in +++ b/bacula/src/cats/update_mysql_tables.in @@ -218,6 +218,12 @@ if [ "$DBVERSION" -eq 16 ] ; then USE ${db_name}; ALTER TABLE Device MODIFY CleaningDate DATETIME DEFAULT NULL; +ALTER TABLE File + MODIFY FileIndex INTEGER DEFAULT 0; +ALTER TABLE RestoreObject + MODIFY FileIndex INTEGER DEFAULT 0; +ALTER TABLE BaseFiles + MODIFY FileIndex INTEGER DEFAULT 0; ALTER TABLE Media MODIFY FirstWritten DATETIME DEFAULT NULL, MODIFY LastWritten DATETIME DEFAULT NULL, diff --git a/bacula/src/cats/update_sqlite3_tables.in b/bacula/src/cats/update_sqlite3_tables.in index 346d92a59..5b1f6e8a0 100644 --- a/bacula/src/cats/update_sqlite3_tables.in +++ b/bacula/src/cats/update_sqlite3_tables.in @@ -247,7 +247,11 @@ DROP TABLE BaseFiles; ALTER TABLE basefiles_temp RENAME TO BaseFiles; CREATE INDEX job_jobtdate_inx ON job (JobTDate); -ALTER TABLE Pool ADD COLUMN CacheRetention BIGINT DEFAULT 0; +ALTER TABLE Pool ADD COLUMN CacheRetention BIGINT DEFAULT 0; +ALTER TABLE File MODIFY FileIndex INTEGER DEFAULT 0; +ALTER TABLE RestoreObject MODIFY FileIndex INTEGER DEFAULT 0; +ALTER TABLE BaseFiles MODIFY FileIndex INTEGER DEFAULT 0; + UPDATE Version SET VersionId=16; COMMIT; diff --git a/bacula/src/dird/bsr.c b/bacula/src/dird/bsr.c index 61de96ddf..aeb136aad 100644 --- a/bacula/src/dird/bsr.c +++ b/bacula/src/dird/bsr.c @@ -514,6 +514,7 @@ void add_findex(rblist *bsr_list, uint32_t JobId, int32_t findex) if (findex == 0) { return; /* probably a dummy directory */ } + if (findex < 0) findex = -findex; bsr2.JobId = JobId; /* Walk down list of bsrs until we find the JobId */ diff --git a/bacula/src/dird/catreq.c b/bacula/src/dird/catreq.c index 88ddd4729..c8e36fc76 100644 --- a/bacula/src/dird/catreq.c +++ b/bacula/src/dird/catreq.c @@ -436,7 +436,7 @@ static void update_attribute(JCR *jcr, char *msg, int32_t msglen) unser_declare; uint32_t VolSessionId, VolSessionTime; int32_t Stream; - uint32_t FileIndex; + int32_t FileIndex; char *p; int len; char *fname, *attr; diff --git a/bacula/src/dird/fd_cmds.c b/bacula/src/dird/fd_cmds.c index 827ea4244..ce594a6cd 100644 --- a/bacula/src/dird/fd_cmds.c +++ b/bacula/src/dird/fd_cmds.c @@ -949,7 +949,7 @@ int get_attributes_and_put_in_catalog(JCR *jcr) Dmsg0(120, "bdird: waiting to receive file attributes\n"); /* Pickup file attributes and digest */ while (!fd->errors && (n = bget_dirmsg(fd)) > 0) { - uint32_t file_index; + int32_t file_index; int stream, len; char *p, *fn; char Digest[MAXSTRING]; /* either Verify opts or MD5/SHA1 digest */ @@ -1018,7 +1018,7 @@ int get_attributes_and_put_in_catalog(JCR *jcr) * At the end, we have to add the last file */ } else if (crypto_digest_stream_type(stream) != CRYPTO_DIGEST_NONE) { - if (jcr->FileIndex != (uint32_t)file_index) { + if (jcr->FileIndex != file_index) { Jmsg3(jcr, M_ERROR, 0, _("%s index %d not same as attributes %d\n"), stream_to_ascii(stream), file_index, jcr->FileIndex); continue; diff --git a/bacula/src/dird/verify.c b/bacula/src/dird/verify.c index 74d5bb07a..5db16b067 100644 --- a/bacula/src/dird/verify.c +++ b/bacula/src/dird/verify.c @@ -803,7 +803,7 @@ void get_attributes_and_compare_to_catalog(JCR *jcr, JobId_t JobId) * When ever we get a digest it MUST have been * preceded by an attributes record, which sets attr_file_index */ - if (jcr->FileIndex != (uint32_t)file_index) { + if (jcr->FileIndex != file_index) { Jmsg2(jcr, M_FATAL, 0, _("MD5/SHA1 index %d not same as attributes %d\n"), file_index, jcr->FileIndex); free_pool_memory(fname); diff --git a/bacula/src/findlib/find_one.c b/bacula/src/findlib/find_one.c index 79fb72dd7..764a3e5ce 100644 --- a/bacula/src/findlib/find_one.c +++ b/bacula/src/findlib/find_one.c @@ -51,7 +51,7 @@ struct f_link { struct f_link *next; dev_t dev; /* device */ ino_t ino; /* inode with device is unique */ - uint32_t FileIndex; /* Bacula FileIndex of this file */ + int32_t FileIndex; /* Bacula FileIndex of this file */ int32_t digest_stream; /* Digest type if needed */ uint32_t digest_len; /* Digest len if needed */ char *digest; /* Checksum of the file if needed */ diff --git a/bacula/src/jcr.h b/bacula/src/jcr.h index 405632676..cc3567230 100644 --- a/bacula/src/jcr.h +++ b/bacula/src/jcr.h @@ -354,7 +354,7 @@ public: volatile int32_t FDJobStatus; /* File daemon Job Status */ uint32_t ExpectedFiles; /* Expected restore files */ uint32_t MediaId; /* DB record IDs associated with this job */ - uint32_t FileIndex; /* Last FileIndex processed */ + int32_t FileIndex; /* Last FileIndex processed */ utime_t MaxRunSchedTime; /* max run time in seconds from Initial Scheduled time */ POOLMEM *fname; /* name to put into catalog */ POOLMEM *component_fname; /* Component info file name */ diff --git a/bacula/src/stored/btape.c b/bacula/src/stored/btape.c index 959bf0c60..69a41dcae 100644 --- a/bacula/src/stored/btape.c +++ b/bacula/src/stored/btape.c @@ -2735,8 +2735,8 @@ static int flush_block(DEV_BLOCK *block, int dump) first_block = dup_block(block); /* first block second tape */ } if (verbose) { - Pmsg3(000, _("Block not written: FileIndex=%u blk_block=%u Size=%u\n"), - (unsigned)file_index, block->BlockNumber, block->block_len); + Pmsg3(000, _("Block not written: FileIndex=%d blk_block=%u Size=%u\n"), + file_index, block->BlockNumber, block->block_len); dump_block(dev, last_block, _("Last block written")); Pmsg0(-1, "\n"); dump_block(dev, block, _("Block not written")); diff --git a/bacula/src/stored/dev.h b/bacula/src/stored/dev.h index 480e1033e..12b5e4275 100644 --- a/bacula/src/stored/dev.h +++ b/bacula/src/stored/dev.h @@ -721,7 +721,7 @@ public: uint32_t VolFirstIndex; /* First file index this Volume */ uint32_t VolLastIndex; /* Last file index this Volume */ - uint32_t FileIndex; /* Current File Index */ + int32_t FileIndex; /* Current File Index */ uint64_t StartAddr; /* Starting write addr */ uint64_t EndAddr; /* Ending write addr */ int64_t VolMediaId; /* MediaId */