trim lintian overrides to only those that remain relevant in this version
[debian/amanda] / server-src / tapefile.c
index 157d65381bae3c67c7d198a0cc6177f80636ef8e..52ece52ee4fba44a0f21f616dc28af4d512cbe42 100644 (file)
@@ -51,7 +51,13 @@ read_tapelist(
 
     tape_list = NULL;
     if((tapef = fopen(tapefile,"r")) == NULL) {
-       return 1;
+       if (errno == ENOENT) {
+           /* no tapelist is equivalent to an empty tapelist */
+           return 0;
+       } else {
+           g_debug("Error opening '%s': %s", tapefile, strerror(errno));
+           return 1;
+       }
     }
 
     while((line = agets(tapef)) != NULL) {
@@ -92,14 +98,16 @@ write_tapelist(
     }
 
     for(tp = tape_list; tp != NULL; tp = tp->next) {
-       fprintf(tapef, "%s %s", tp->datestamp, tp->label);
-       if(tp->reuse) fprintf(tapef, " reuse");
-       else fprintf(tapef, " no-reuse");
-       fprintf(tapef, "\n");
+       g_fprintf(tapef, "%s %s", tp->datestamp, tp->label);
+       if(tp->reuse) g_fprintf(tapef, " reuse");
+       else g_fprintf(tapef, " no-reuse");
+       if (tp->comment)
+           g_fprintf(tapef, " #%s", tp->comment);
+       g_fprintf(tapef, "\n");
     }
 
     if (fclose(tapef) == EOF) {
-       fprintf(stderr,"error [closing %s: %s]", newtapefile, strerror(errno));
+       g_fprintf(stderr,_("error [closing %s: %s]"), newtapefile, strerror(errno));
        amfree(newtapefile);
        return 1;
     }
@@ -258,7 +266,8 @@ remove_tapelabel(
 tape_t *
 add_tapelabel(
     char *datestamp,
-    char *label)
+    char *label,
+    char *comment)
 {
     tape_t *cur, *new;
 
@@ -270,6 +279,7 @@ add_tapelabel(
     new->position = 0;
     new->reuse = 1;
     new->label = stralloc(label);
+    new->comment = comment? stralloc(comment) : NULL;
 
     new->prev  = NULL;
     if(tape_list != NULL) tape_list->prev = new;
@@ -362,10 +372,26 @@ parse_tapeline(
 
     skip_whitespace(s, ch);
     tp->reuse = 1;
-    if(strncmp_const(s - 1, "reuse") == 0)
+    if(strncmp_const(s - 1, "reuse") == 0) {
        tp->reuse = 1;
-    if(strncmp_const(s - 1, "no-reuse") == 0)
+       s1 = s - 1;
+       skip_non_whitespace(s, ch);
+       s[-1] = '\0';
+       skip_whitespace(s, ch);
+    }
+    if(strncmp_const(s - 1, "no-reuse") == 0) {
        tp->reuse = 0;
+       s1 = s - 1;
+       skip_non_whitespace(s, ch);
+       s[-1] = '\0';
+       skip_whitespace(s, ch);
+    }
+
+    if (*(s - 1) == '#') {
+       tp->comment = stralloc(s); /* skip leading '#' */
+    } else {
+       tp->comment = NULL;
+    }
 
     return tp;
 }
@@ -443,3 +469,49 @@ stamp2time(
 
     return mktime(tm);
 }
+
+void
+print_new_tapes(
+    FILE *output,
+    int   nb)
+{
+    tape_t *lasttp, *iter;
+
+    /* Find latest reusable new tape */
+    lasttp = lookup_tapepos(lookup_nb_tape());
+    while (lasttp && lasttp->reuse == 0)
+       lasttp = lasttp->prev;
+
+    if(lasttp && nb > 0 && strcmp(lasttp->datestamp,"0") == 0) {
+       int c = 0;
+       iter = lasttp;
+       /* count the number of tapes we *actually* used */
+       while(iter && nb > 0 && strcmp(iter->datestamp,"0") == 0) {
+           if (iter->reuse) {
+               c++;
+               nb--;
+           }
+           iter = iter->prev;
+       }
+
+       if(c == 1) {
+           g_fprintf(output,
+                     _("The next new tape already labelled is: %s.\n"),
+                     lasttp->label);
+       } else {
+           g_fprintf(output,
+                     _("The next %d new tapes already labelled are: %s"),
+                     c, lasttp->label);
+           iter = lasttp->prev;
+           c--;
+           while(iter && c > 0 && strcmp(iter->datestamp,"0") == 0) {
+               if (iter->reuse) {
+                   g_fprintf(output, ", %s", iter->label);
+                   c--;
+               }
+               iter = iter->prev;
+           }
+           g_fprintf(output, ".\n");
+       }
+    }
+}