1 /* $Id: update_path.c,v 1.3 2007-01-15 15:10:17 adam Exp $
2 Copyright (C) 1995-2007
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 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, int deleteFlag, char *rep,
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, deleteFlag);
69 repositoryExtractR (zh, deleteFlag, rep, level+1);
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,
110 int deleteFlag, const char *path)
118 if (zh->path_reg && !yaz_is_abspath(path))
120 strcpy (src, zh->path_reg);
126 ret = zebra_file_stat (src, &sbuf, zh->m_follow_links);
131 yaz_log (YLOG_WARN|YLOG_ERRNO, "Cannot access path %s", src);
132 else if (S_ISREG(sbuf.st_mode))
133 zebra_extract_file (zh, NULL, src, deleteFlag);
134 else if (S_ISDIR(sbuf.st_mode))
135 repositoryExtractR (zh, deleteFlag, src, 0);
137 yaz_log (YLOG_WARN, "Skipping path %s", src);
140 static void repositoryExtractG(ZebraHandle zh, const char *path,
143 if (!strcmp(path, "") || !strcmp(path, "-"))
147 while (scanf("%1020s", src) == 1)
148 repositoryExtract(zh, deleteFlag, src);
151 repositoryExtract(zh, deleteFlag, path);
154 ZEBRA_RES zebra_update_from_path(ZebraHandle zh, const char *path)
157 repositoryExtractG(zh, path, 0);
161 ZEBRA_RES zebra_delete_from_path(ZebraHandle zh, const char *path)
164 repositoryExtractG(zh, path, 1);
171 * indent-tabs-mode: nil
173 * vim: shiftwidth=4 tabstop=8 expandtab