1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2011 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
25 #include <sys/types.h>
28 #define S_ISREG(x) (x & _S_IFREG)
29 #define S_ISDIR(x) (x & _S_IFDIR)
40 static void repositoryExtractR(ZebraHandle zh, char *rep, int level,
41 enum zebra_recctrl_action_t action)
45 size_t rep_len = strlen(rep);
47 e = dir_open(rep, zh->path_reg, zh->m_follow_links);
50 yaz_log(YLOG_LOG, "dir %s", rep);
51 if (rep[rep_len-1] != '/')
56 for (i=0; e[i].name; i++)
59 strcpy(rep +rep_len+1, e[i].name);
60 if ((ecp = strrchr(e[i].name, '/')))
66 zebra_extract_file(zh, NULL, rep, action);
69 repositoryExtractR(zh, rep, level+1, action);
77 void repositoryShow(ZebraHandle zh, const char *path)
81 struct dirs_entry *dst;
85 if (!(dict = dict_open_res(zh->reg->bfs, FMATCH_DICT, 50, 0, 0, zh->res)))
87 yaz_log(YLOG_FATAL, "dict_open fail of %s", FMATCH_DICT);
91 strncpy(src, path, sizeof(src)-1);
92 src[sizeof(src)-1]='\0';
93 src_len = strlen(src);
95 if (src_len && src[src_len-1] != '/')
98 src[++src_len] = '\0';
101 di = dirs_open(dict, src, zh->m_flag_rw);
103 while ((dst = dirs_read(di)))
104 yaz_log(YLOG_LOG, "%s", dst->path);
109 static void repositoryExtract(ZebraHandle zh,
111 enum zebra_recctrl_action_t action)
120 if (zh->path_reg && !yaz_is_abspath(path))
122 strcpy(src, zh->path_reg);
128 ret = zebra_file_stat(src, &sbuf, zh->m_follow_links);
133 yaz_log(YLOG_WARN|YLOG_ERRNO, "Cannot access path %s", src);
134 else if (S_ISREG(sbuf.st_mode))
135 zebra_extract_file(zh, NULL, src, action);
136 else if (S_ISDIR(sbuf.st_mode))
137 repositoryExtractR(zh, src, 0, action);
139 yaz_log(YLOG_WARN, "Skipping path %s", src);
143 ZEBRA_RES zebra_update_from_path(ZebraHandle zh, const char *path,
144 enum zebra_recctrl_action_t action)
146 if (!strcmp(path, "") || !strcmp(path, "-"))
150 while (scanf("%1020s", src) == 1)
151 repositoryExtract(zh, src, action);
154 repositoryExtract(zh, path, action);
161 * c-file-style: "Stroustrup"
162 * indent-tabs-mode: nil
164 * vim: shiftwidth=4 tabstop=8 expandtab