+
+
+static int
+get_index_dir(
+ char *dump_hostname,
+ char *hostname,
+ char *diskname)
+{
+ struct stat dir_stat;
+ char *fn;
+ char *s;
+ char *lower_hostname;
+
+ lower_hostname = stralloc(dump_hostname);
+ for(s=lower_hostname; *s != '\0'; s++)
+ *s = tolower(*s);
+
+ fn = getindexfname(dump_hostname, diskname, NULL, 0);
+ if (stat(fn, &dir_stat) == 0 && S_ISDIR(dir_stat.st_mode)) {
+ amfree(lower_hostname);
+ amfree(fn);
+ return 1;
+ }
+ amfree(fn);
+ if (hostname != NULL) {
+ fn = getindexfname(hostname, diskname, NULL, 0);
+ if (stat(fn, &dir_stat) == 0 && S_ISDIR(dir_stat.st_mode)) {
+ amfree(lower_hostname);
+ amfree(fn);
+ return 1;
+ }
+ }
+ amfree(fn);
+ fn = getindexfname(lower_hostname, diskname, NULL, 0);
+ if (stat(fn, &dir_stat) == 0 && S_ISDIR(dir_stat.st_mode)) {
+ amfree(lower_hostname);
+ amfree(fn);
+ return 1;
+ }
+ amfree(fn);
+ if(diskname != NULL) {
+ fn = getoldindexfname(dump_hostname, diskname, NULL, 0);
+ if (stat(fn, &dir_stat) == 0 && S_ISDIR(dir_stat.st_mode)) {
+ amfree(lower_hostname);
+ amfree(fn);
+ return 1;
+ }
+ amfree(fn);
+ if (hostname != NULL) {
+ fn = getoldindexfname(hostname, diskname, NULL, 0);
+ if (stat(fn, &dir_stat) == 0 && S_ISDIR(dir_stat.st_mode)) {
+ amfree(lower_hostname);
+ amfree(fn);
+ return 1;
+ }
+ }
+ amfree(fn);
+ fn = getoldindexfname(lower_hostname, diskname, NULL, 0);
+ if (stat(fn, &dir_stat) == 0 && S_ISDIR(dir_stat.st_mode)) {
+ amfree(lower_hostname);
+ amfree(fn);
+ return 1;
+ }
+ amfree(fn);
+ }
+ amfree(lower_hostname);
+ return -1;
+}
+
+static char *
+get_index_name(
+ char *dump_hostname,
+ char *hostname,
+ char *diskname,
+ char *timestamps,
+ int level)
+{
+ struct stat dir_stat;
+ char *fn;
+ char *s;
+ char *lower_hostname;
+
+ lower_hostname = stralloc(dump_hostname);
+ for(s=lower_hostname; *s != '\0'; s++)
+ *s = tolower(*s);
+
+ fn = getindexfname(dump_hostname, diskname, timestamps, level);
+ if (stat(fn, &dir_stat) == 0 && S_ISREG(dir_stat.st_mode)) {
+ amfree(lower_hostname);
+ return fn;
+ }
+ amfree(fn);
+ if(hostname != NULL) {
+ fn = getindexfname(hostname, diskname, timestamps, level);
+ if (stat(fn, &dir_stat) == 0 && S_ISREG(dir_stat.st_mode)) {
+ amfree(lower_hostname);
+ return fn;
+ }
+ }
+ amfree(fn);
+ fn = getindexfname(lower_hostname, diskname, timestamps, level);
+ if (stat(fn, &dir_stat) == 0 && S_ISREG(dir_stat.st_mode)) {
+ amfree(lower_hostname);
+ return fn;
+ }
+ amfree(fn);
+ if(diskname != NULL) {
+ fn = getoldindexfname(dump_hostname, diskname, timestamps, level);
+ if (stat(fn, &dir_stat) == 0 && S_ISREG(dir_stat.st_mode)) {
+ amfree(lower_hostname);
+ return fn;
+ }
+ amfree(fn);
+ if(hostname != NULL) {
+ fn = getoldindexfname(hostname, diskname, timestamps, level);
+ if (stat(fn, &dir_stat) == 0 && S_ISREG(dir_stat.st_mode)) {
+ amfree(lower_hostname);
+ return fn;
+ }
+ }
+ amfree(fn);
+ fn = getoldindexfname(lower_hostname, diskname, timestamps, level);
+ if (stat(fn, &dir_stat) == 0 && S_ISREG(dir_stat.st_mode)) {
+ amfree(lower_hostname);
+ return fn;
+ }
+ }
+ amfree(lower_hostname);
+ return NULL;
+}