]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Permit catalog to contain negative FileIndexes
authorKern Sibbald <kern@sibbald.com>
Sat, 11 Aug 2018 19:20:22 +0000 (21:20 +0200)
committerKern Sibbald <kern@sibbald.com>
Sat, 11 Aug 2018 19:20:32 +0000 (21:20 +0200)
20 files changed:
bacula/src/cats/bvfs.c
bacula/src/cats/cats.h
bacula/src/cats/make_mysql_tables.in
bacula/src/cats/make_postgresql_tables.in
bacula/src/cats/make_sqlite3_tables.in
bacula/src/cats/mysql.c
bacula/src/cats/sql_cmds.c
bacula/src/cats/sql_create.c
bacula/src/cats/sql_get.c
bacula/src/cats/sql_list.c
bacula/src/cats/update_mysql_tables.in
bacula/src/cats/update_sqlite3_tables.in
bacula/src/dird/bsr.c
bacula/src/dird/catreq.c
bacula/src/dird/fd_cmds.c
bacula/src/dird/verify.c
bacula/src/findlib/find_one.c
bacula/src/jcr.h
bacula/src/stored/btape.c
bacula/src/stored/dev.h

index afd4fa33017aa55d09ca9ff4c193be4f42a9a613..787b1a72b1409bff7cd10255f8836410c4656e6b 100644 (file)
@@ -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) "
index a1223bab7cebbf3922c159e7df99cc2dd6428515..bb102bd60cf38cfbf53612dc891d1a65e0a08588 100644 (file)
@@ -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;
index db5fc9ebab974381072d418cc3be436a6b75707c..f41a6345f3fcde7bb15b60bee66a148babb7e274 100644 (file)
@@ -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)
    );
 
index 43833c4a9f0548a06d6bb214db0a5d10c85aee4d..4196d074587f7a19c5b1d49df7065b591902dc03 100644 (file)
@@ -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)
 );
index c5f3b09c2edb4744923b278914b3dd03426f9281..844ae54da2a6d1cde9601d0954e67d02b6124500 100644 (file)
@@ -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)
    );
 
index 5abfa43901b3ef96c895abf89cb8e5ba53aecdc2..d3a0c46f40f4c56b22383a68f8365cfcd75d89d5 100644 (file)
@@ -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); 
index 06b23b25301e47c912599cfc55eb454781b1089f..5fe303153b594260669240be1ad65ba51117e0df 100644 (file)
@@ -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.
index 5f72baceeff2235c141309ae862a4e1f210a121c..57881472927f3e3e22cd18c9a76d10a10763d1a2 100644 (file)
@@ -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);
 
index 201017bcd0d3984648b5473f13ac342fe77f2399..85c5df549f4930854fdc92d5c8b863fba2104da4 100644 (file)
@@ -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),
index 0090a25490602a0ddeb85ef19c6a895dd2206b7a..20ab42f048537c829ee9760c199660a5a39d08bc 100644 (file)
@@ -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 = "";
index 81e9163b6e51c647f6bffd613fb4b71ca777c991..2dbc3434ad8bceff40adfcd212051bffa2c04afc 100644 (file)
@@ -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,
index 346d92a5963a814b0d2a97beb59b420840f14460..5b1f6e8a0c58fba658911d017a7e191a599ef5c1 100644 (file)
@@ -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;
index 61de96ddfe77a622ae7ef3e10a3020e5ad7333c0..aeb136aad342189ec67cd949dff9ec0cb7e49d35 100644 (file)
@@ -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 */
index 88ddd4729680c75937990e21f396aa26731733dc..c8e36fc76977bea9fd04c9e210584f89da5e4c6f 100644 (file)
@@ -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;
index 827ea42448898f8bcbc6f1cb22f57c68785322a5..ce594a6cd07aeb211023ddf9c86f7c179347bc05 100644 (file)
@@ -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;
index 74d5bb07a0c10d1b834ccab961afdaba5f4767c4..5db16b06768a97a65961d5ff9b495114dde58361 100644 (file)
@@ -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);
index 79fb72dd7337095354fef422ffe1f17a7fb0acfd..764a3e5ce5edd328d69857fb053f1fc0c7aad3e2 100644 (file)
@@ -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 */
index 405632676ad27f8d886f2fe58b14b4864acdb837..cc35672305b0ae1bca31d1df22f84115d10e444e 100644 (file)
@@ -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 */
index 959bf0c60bd9a4465a7ca57d4b5cfeaf9e86b1d5..69a41dcaec04c0f9c104385fcc855027386840fe 100644 (file)
@@ -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"));
index 480e1033e10fdba9af8089540b19cd1116924e8b..12b5e42753a0ea36f92f92b4f1e0f96c8f59a5e3 100644 (file)
@@ -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 */