- /* stick that list in a structure that librestore will understand */
- for(curtape = needed_tapes; curtape; curtape = curtape->next) {
- find_result_t *curfind = NULL;
- for(curfind = curtape->files; curfind; curfind = curfind->next) {
- tapes = append_to_tapelist(tapes, curtape->label,
- curfind->filenum, -1, curtape->isafile);
+ /* sort the tapelist by tape write_timestamp */
+ needed_tapes = g_slist_sort(needed_tapes, sort_needed_tapes_by_write_timestamp);
+
+ /* stick that list in a structure that librestore will understand, removing
+ * files we have already seen in the process; this prefers the earliest written
+ * copy of any dumps which are available on multiple tapes */
+ seen_dumps = NULL;
+ for(iter = needed_tapes; iter; iter = iter->next) {
+ needed_tape_t *curtape = iter->data;
+ for(iter2 = curtape->files; iter2; iter2 = iter2->next) {
+ find_result_t *curfind = iter2->data;
+ find_result_t *prev;
+ GSList *iter;
+ int have_part;
+
+ /* have we already seen this? */
+ have_part = 0;
+ for (iter = seen_dumps; iter; iter = iter->next) {
+ prev = iter->data;
+
+ if (!strcmp(prev->partnum, curfind->partnum) &&
+ !strcmp(prev->hostname, curfind->hostname) &&
+ !strcmp(prev->diskname, curfind->diskname) &&
+ !strcmp(prev->timestamp, curfind->timestamp) &&
+ prev->level == curfind->level) {
+ have_part = 1;
+ break;
+ }
+ }
+
+ if (!have_part) {
+ seen_dumps = g_slist_prepend(seen_dumps, curfind);
+ tapes = append_to_tapelist(tapes, curtape->label,
+ curfind->filenum, -1, curtape->isafile);
+ }