lintian doesn't like orphan packages with uploaders...
[debian/amanda] / server-src / list_dir.c
index c38a30639b6d84876d7c59075ff33d4df2b47eeb..a909067e64be4db1283e705227a15afcb58a4387 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: list_dir.c,v 1.17 2002/03/24 19:25:51 jrjackson Exp $
+/* $Id: list_dir.c,v 1.19 2006/07/05 11:22:49 martinea Exp $
  *
  * manage directory listings from index files
  */
@@ -36,13 +37,15 @@ DIR_ITEM *dir_list = NULL; /* first dir entry */
 DIR_ITEM *dir_last = NULL; /* last dir entry  */
 DIR_ITEM *cur_list = NULL; /* current dir entry,for speeding up search */
 
-DIR_ITEM *get_dir_list()
+DIR_ITEM *
+get_dir_list(void)
 {
     return dir_list;
 }
 
 
-void clear_dir_list P((void))
+void
+clear_dir_list(void)
 {
     DIR_ITEM *this;
 
@@ -68,15 +71,17 @@ void clear_dir_list P((void))
 /* It's true because the output of the index file is sorted         */
 /* Maybe it could be more efficient if the index was sorted when    */
 /* it is generated                                                  */
-int add_dir_list_item(dump, path)
-DUMP_ITEM *dump;
-char *path;
+
+int
+add_dir_list_item(
+    DUMP_ITEM *        dump,
+    const char *path)
 {
     DIR_ITEM *cur;
 
     if (dir_list == NULL)
     {
-       dir_list = (DIR_ITEM *)alloc(sizeof(DIR_ITEM));
+       dir_list = (DIR_ITEM *)alloc(SIZEOF(DIR_ITEM));
        dir_list->next = NULL;
        dir_list->dump = dump;
        dir_list->path = stralloc(path);
@@ -85,13 +90,15 @@ char *path;
        return 0; /* added */
     }
 
-    if(strcmp(path,dir_last->path) == 0)
+    if (strcmp(path, "/") != 0 &&
+       strcmp(path, dir_last->path) == 0) {
        return 0; /* found */
+    }
 
     /* add at head of list */
     if(strcmp(path,dir_list->path) < 0)
     {
-       cur_list = (DIR_ITEM *)alloc(sizeof(DIR_ITEM));
+       cur_list = (DIR_ITEM *)alloc(SIZEOF(DIR_ITEM));
        cur_list->next = dir_list;
        cur_list->dump = dump;
        cur_list->path = stralloc(path);
@@ -117,14 +124,14 @@ char *path;
            cur_list=cur_list->next;
        }
 
-       if(strcmp(path,cur_list->next->path) == 0)
+       if (cur_list->next && strcmp(path, cur_list->next->path) == 0)
        {
            cur_list=cur_list->next;
            return 0; /* found */
        }
 
        /* add at cur_list */
-       cur = (DIR_ITEM *)alloc(sizeof(DIR_ITEM));
+       cur = (DIR_ITEM *)alloc(SIZEOF(DIR_ITEM));
        cur->next = cur_list->next;
        cur->dump = dump;
        cur->path = stralloc(path);
@@ -134,7 +141,7 @@ char *path;
     }
     else /* add at end of list */
     {
-       dir_last->next = (DIR_ITEM *)alloc(sizeof(DIR_ITEM));
+       dir_last->next = (DIR_ITEM *)alloc(SIZEOF(DIR_ITEM));
        dir_last=dir_last->next;
        dir_last->next = NULL;
        dir_last->dump = dump;