2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1991-1998 University of Maryland at College Park
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of U.M. not be used in advertising or
11 * publicity pertaining to distribution of the software without specific,
12 * written prior permission. U.M. makes no representations about the
13 * suitability of this software for any purpose. It is provided "as is"
14 * without express or implied warranty.
16 * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Authors: the Amanda Development Team. Its members are listed in a
24 * file named AUTHORS, in the root directory of this distribution.
26 /* $Id: list_dir.c,v 1.19 2006/07/05 11:22:49 martinea Exp $
28 * manage directory listings from index files
32 #include "disk_history.h"
35 DIR_ITEM *dir_list = NULL; /* first dir entry */
36 DIR_ITEM *dir_last = NULL; /* last dir entry */
37 DIR_ITEM *cur_list = NULL; /* current dir entry,for speeding up search */
57 dir_list = dir_list->next;
60 } while (dir_list != NULL);
66 /* add item to list if path not already on list */
67 /* Since this function is almost called with increasing path order, */
68 /* we keep a pointer on the last element added (cur_list), this */
69 /* reduce the time for the search of a path. */
70 /* It's true because the output of the index file is sorted */
71 /* Maybe it could be more efficient if the index was sorted when */
83 dir_list = (DIR_ITEM *)alloc(SIZEOF(DIR_ITEM));
84 dir_list->next = NULL;
85 dir_list->dump = dump;
86 dir_list->path = stralloc(path);
92 if(strcmp(path,dir_last->path) == 0)
95 /* add at head of list */
96 if(strcmp(path,dir_list->path) < 0)
98 cur_list = (DIR_ITEM *)alloc(SIZEOF(DIR_ITEM));
99 cur_list->next = dir_list;
100 cur_list->dump = dump;
101 cur_list->path = stralloc(path);
103 return 0; /* added */
106 /* if smaller than last path */
107 if(strcmp(path,dir_last->path) < 0)
112 /* reset cur_list if path is smaller than cur_list->path */
113 if(strcmp(path,cur_list->path) < 0)
116 if(strcmp(path,cur_list->path) == 0)
117 return 0; /* found */
119 while (cur_list->next!=NULL && (strcmp(path,cur_list->next->path) > 0))
121 cur_list=cur_list->next;
124 if (cur_list->next && strcmp(path, cur_list->next->path) == 0)
126 cur_list=cur_list->next;
127 return 0; /* found */
130 /* add at cur_list */
131 cur = (DIR_ITEM *)alloc(SIZEOF(DIR_ITEM));
132 cur->next = cur_list->next;
134 cur->path = stralloc(path);
137 return 0; /* added */
139 else /* add at end of list */
141 dir_last->next = (DIR_ITEM *)alloc(SIZEOF(DIR_ITEM));
142 dir_last=dir_last->next;
143 dir_last->next = NULL;
144 dir_last->dump = dump;
145 dir_last->path = stralloc(path);
146 return 0; /* added */