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, "/") != 0 &&
93 strcmp(path, dir_last->path) == 0) {
97 /* add at head of list */
98 if(strcmp(path,dir_list->path) < 0)
100 cur_list = (DIR_ITEM *)alloc(SIZEOF(DIR_ITEM));
101 cur_list->next = dir_list;
102 cur_list->dump = dump;
103 cur_list->path = stralloc(path);
105 return 0; /* added */
108 /* if smaller than last path */
109 if(strcmp(path,dir_last->path) < 0)
114 /* reset cur_list if path is smaller than cur_list->path */
115 if(strcmp(path,cur_list->path) < 0)
118 if(strcmp(path,cur_list->path) == 0)
119 return 0; /* found */
121 while (cur_list->next!=NULL && (strcmp(path,cur_list->next->path) > 0))
123 cur_list=cur_list->next;
126 if (cur_list->next && strcmp(path, cur_list->next->path) == 0)
128 cur_list=cur_list->next;
129 return 0; /* found */
132 /* add at cur_list */
133 cur = (DIR_ITEM *)alloc(SIZEOF(DIR_ITEM));
134 cur->next = cur_list->next;
136 cur->path = stralloc(path);
139 return 0; /* added */
141 else /* add at end of list */
143 dir_last->next = (DIR_ITEM *)alloc(SIZEOF(DIR_ITEM));
144 dir_last=dir_last->next;
145 dir_last->next = NULL;
146 dir_last->dump = dump;
147 dir_last->path = stralloc(path);
148 return 0; /* added */