1 /* This file is part of the Zebra server.
2 Copyright (C) 1995-2008 Index Data
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <sys/types.h>
25 #define S_ISREG(x) (x & _S_IFREG)
26 #define S_ISDIR(x) (x & _S_IFDIR)
37 static void repositoryExtractR(ZebraHandle zh, char *rep, int level,
38 enum zebra_recctrl_action_t action)
42 size_t rep_len = strlen(rep);
44 e = dir_open(rep, zh->path_reg, zh->m_follow_links);
47 yaz_log(YLOG_LOG, "dir %s", rep);
48 if (rep[rep_len-1] != '/')
53 for (i=0; e[i].name; i++)
56 strcpy(rep +rep_len+1, e[i].name);
57 if ((ecp = strrchr(e[i].name, '/')))
63 zebra_extract_file(zh, NULL, rep, action);
66 repositoryExtractR(zh, rep, level+1, action);
74 void repositoryShow(ZebraHandle zh, const char *path)
78 struct dirs_entry *dst;
82 if (!(dict = dict_open_res(zh->reg->bfs, FMATCH_DICT, 50, 0, 0, zh->res)))
84 yaz_log(YLOG_FATAL, "dict_open fail of %s", FMATCH_DICT);
88 strncpy(src, path, sizeof(src)-1);
89 src[sizeof(src)-1]='\0';
90 src_len = strlen(src);
92 if (src_len && src[src_len-1] != '/')
95 src[++src_len] = '\0';
98 di = dirs_open(dict, src, zh->m_flag_rw);
100 while ((dst = dirs_read(di)))
101 yaz_log(YLOG_LOG, "%s", dst->path);
106 static void repositoryExtract(ZebraHandle zh,
108 enum zebra_recctrl_action_t action)
117 if (zh->path_reg && !yaz_is_abspath(path))
119 strcpy(src, zh->path_reg);
125 ret = zebra_file_stat(src, &sbuf, zh->m_follow_links);
130 yaz_log(YLOG_WARN|YLOG_ERRNO, "Cannot access path %s", src);
131 else if (S_ISREG(sbuf.st_mode))
132 zebra_extract_file(zh, NULL, src, action);
133 else if (S_ISDIR(sbuf.st_mode))
134 repositoryExtractR(zh, src, 0, action);
136 yaz_log(YLOG_WARN, "Skipping path %s", src);
140 ZEBRA_RES zebra_update_from_path(ZebraHandle zh, const char *path,
141 enum zebra_recctrl_action_t action)
143 if (!strcmp(path, "") || !strcmp(path, "-"))
147 while (scanf("%1020s", src) == 1)
148 repositoryExtract(zh, src, action);
151 repositoryExtract(zh, path, action);
158 * indent-tabs-mode: nil
160 * vim: shiftwidth=4 tabstop=8 expandtab