lintian doesn't like orphan packages with uploaders...
[debian/amanda] / server-src / disk_history.c
index 8d465bb8e5c8201663fede3bbb002a16334b2c5b..5b5de24a085d9e23ae6652792adb1f20fae97b47 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Amanda, The Advanced Maryland Automatic Network Disk Archiver
  * Copyright (c) 1991-1998 University of Maryland at College Park
+ * Copyright (c) 2007-2012 Zmanda, Inc.  All Rights Reserved.
  * All Rights Reserved.
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
@@ -23,7 +24,7 @@
  * Authors: the Amanda Development Team.  Its members are listed in a
  * file named AUTHORS, in the root directory of this distribution.
  */
-/* $Id: disk_history.c,v 1.12 2006/01/16 00:07:01 martinea Exp $
+/* $Id: disk_history.c,v 1.13 2006/05/25 01:47:19 johnfranks Exp $
  *
  * functions for obtaining backup history
  */
@@ -33,7 +34,8 @@
 
 static DUMP_ITEM *disk_hist = NULL;
 
-void clear_list P((void))
+void
+clear_list(void)
 {
     DUMP_ITEM *item, *this;
 
@@ -42,6 +44,7 @@ void clear_list P((void))
     {
        this = item;
        item = item->next;
+       amfree(this->hostname);
        while(this->tapes != NULL) {
            tapelist_t *tapes = this->tapes;
            this->tapes = tapes->next;
@@ -55,51 +58,63 @@ void clear_list P((void))
 }
 
 /* add item, maintain list ordered by oldest date last */
-void add_dump(date, level, tape, file, partnum)
-char *date;
-int level;
-char *tape;
-int file;
-int partnum;
+
+void
+add_dump(
+    char *      hostname,
+    char *     date,
+    int                level,
+    char *     tape,
+    off_t      file,
+    int                partnum,
+    int                maxpart)
 {
     DUMP_ITEM *new, *item, *before;
     int isafile = 0;
 
-    new = (DUMP_ITEM *)alloc(sizeof(DUMP_ITEM));
-    strncpy(new->date, date, sizeof(new->date)-1);
-    new->date[sizeof(new->date)-1] = '\0';
+    if(tape[0] == '/')
+       isafile = 1; /* XXX kludgey, like this whole thing */
+
+    /* See if we already have partnum=partnum-1 */
+    if (partnum > 1) {
+       for(item = disk_hist, before = NULL; item;
+           before = item, item = item->next) {
+           if (!strcmp(item->date, date) &&
+                   item->level == level && item->is_split) {
+               item->tapes = append_to_tapelist(item->tapes, tape, file,
+                                                partnum, isafile);
+               if (maxpart > item->maxpart)
+                   item->maxpart = maxpart;
+               return;
+           }
+       }
+       return;
+    }
+
+    new = (DUMP_ITEM *)alloc(SIZEOF(DUMP_ITEM));
+    strncpy(new->date, date, SIZEOF(new->date)-1);
+    new->date[SIZEOF(new->date)-1] = '\0';
     new->level = level;
-    strncpy(new->tape, tape, sizeof(new->tape)-1);
-    new->tape[sizeof(new->tape)-1] = '\0';
+    strncpy(new->tape, tape, SIZEOF(new->tape)-1);
+    new->tape[SIZEOF(new->tape)-1] = '\0';
     new->file = file;
-    if(partnum == -1) new->is_split = 0;
-    else new->is_split = 1;
+    new->maxpart = maxpart;
+    if(partnum == -1)
+        new->is_split = 0;
+    else
+        new->is_split = 1;
     new->tapes = NULL;
+    new->hostname = stralloc(hostname);
 
-   if(new->tape[0] == '/') isafile = 1; /* XXX kludgey, like this whole thing */
+    new->tapes = append_to_tapelist(new->tapes, tape, file, partnum, isafile);
 
     if (disk_hist == NULL)
     {
        disk_hist = new;
-       new->tapes = append_to_tapelist(new->tapes, tape, file, isafile);
        new->next = NULL;
        return;
     }
 
-    /* see if we already have part of this dump somewhere */
-    if(new->is_split){
-       for(item = disk_hist; item; item = item->next){
-           if (!strcmp(item->date, new->date) &&
-                   item->level == new->level && item->is_split){
-               item->tapes = append_to_tapelist(item->tapes, tape, file, isafile);
-               amfree(new);
-               return;
-           }
-       }
-    }
-
-    new->tapes = append_to_tapelist(new->tapes, tape, file, isafile);
-
     /* prepend this item to the history list, if it's newer */
     /* XXX this should probably handle them being on the same date with
        datestamp_uax or something */
@@ -122,14 +137,47 @@ int partnum;
     before->next = new;
 }
 
-
-DUMP_ITEM *first_dump P((void))
+void
+clean_dump(void)
 {
-    return disk_hist;
+    DUMP_ITEM *item, *before;
+
+    /* check if the maxpart part is avaliable */
+    for(item = disk_hist, before = NULL; item;
+                                        before = item, item = item->next) {
+       int found_maxpart = 0;
+       tapelist_t *cur_tape;
+
+       if (item->maxpart > 1) {
+           for (cur_tape = item->tapes; cur_tape; cur_tape = cur_tape->next) {
+               int files;
+               for(files=0; files<cur_tape->numfiles; files++) {
+                   if (cur_tape->partnum[files] == item->maxpart) {
+                       found_maxpart = 1;
+                   }
+               }
+           }
+           if (found_maxpart == 0) {
+               DUMP_ITEM *myitem = item; 
+
+               if (before)
+                   before->next = item->next;
+               else
+                   disk_hist = item->next;
+               item = item->next;
+               /* free myitem */
+               free_tapelist(myitem->tapes);
+               amfree(myitem->hostname);
+               amfree(myitem);
+               if (item == NULL)
+                   break;
+           }
+       }
+    }
 }
 
-DUMP_ITEM *next_dump(item)
-DUMP_ITEM *item;
+DUMP_ITEM *
+first_dump(void)
 {
-    return item->next;
+    return disk_hist;
 }