-/* $Id: trav.c,v 1.40 2002-08-02 19:26:55 adam Exp $
- Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
+/* $Id: trav.c,v 1.43 2003-10-20 19:26:05 adam Exp $
+ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003
Index Data Aps
This file is part of the Zebra server.
02111-1307, USA.
*/
-
-
-
#include <stdio.h>
#include <assert.h>
#include <sys/types.h>
-#include <sys/stat.h>
#ifdef WIN32
#include <io.h>
#define S_ISREG(x) (x & _S_IFREG)
int i;
size_t rep_len = strlen (rep);
- e = dir_open (rep, zh->path_reg);
+ e = dir_open (rep, zh->path_reg, rGroup->followLinks);
if (!e)
return;
- logf (LOG_LOG, "dir %s", rep);
+ yaz_log (LOG_LOG, "dir %s", rep);
if (rep[rep_len-1] != '/')
rep[rep_len] = '/';
else
size_t src_len = strlen (src);
sprintf (tmppath, "%s%s", base, src);
- e_src = dir_open (tmppath, zh->path_reg);
- logf (LOG_LOG, "dir %s", tmppath);
+ e_src = dir_open (tmppath, zh->path_reg, rGroup->followLinks);
+ yaz_log (LOG_LOG, "dir %s", tmppath);
#if 0
if (!dst || repComp (dst->path, src, src_len))
{
if (e_src[i_src].name)
{
- logf (LOG_DEBUG, "dst=%s src=%s", dst->path + src_len,
+ yaz_log (LOG_DEBUG, "dst=%s src=%s", dst->path + src_len,
e_src[i_src].name);
sd = strcmp (dst->path + src_len, e_src[i_src].name);
}
sd = 1;
else
break;
- logf (LOG_DEBUG, "trav sd=%d", sd);
+ yaz_log (LOG_DEBUG, "trav sd=%d", sd);
if (level == 0 && rGroup->databaseNamePath)
rGroup->databaseName = e_src[i_src].name;
{
dirs_add (di, src, dst->sysno, e_src[i_src].mtime);
}
- logf (LOG_DEBUG, "old: %s", ctime (&dst->mtime));
- logf (LOG_DEBUG, "new: %s", ctime (&e_src[i_src].mtime));
+ yaz_log (LOG_DEBUG, "old: %s", ctime (&dst->mtime));
+ yaz_log (LOG_DEBUG, "new: %s", ctime (&e_src[i_src].mtime));
}
dst = dirs_read (di);
break;
case dirs_dir:
fileUpdateR (zh, di, dst, base, src, rGroup, level+1);
dst = dirs_last (di);
- logf (LOG_DEBUG, "last is %s", dst ? dst->path : "null");
+ yaz_log (LOG_DEBUG, "last is %s", dst ? dst->path : "null");
break;
default:
dst = dirs_read (di);
sprintf (resStr, "%sdatabasePath", gPrefix);
rGroup->databaseNamePath =
atoi (res_get_def (zh->res, resStr, "0"));
+
+ rGroup->databaseNamePath =
+ atoi (res_get_def (zh->res, resStr, "0"));
+
+ if (rGroup->followLinks == -1)
+ {
+ sprintf (resStr, "%sfollowLinks", gPrefix);
+ rGroup->followLinks =
+ atoi (res_get_def (zh->res, resStr, "1"));
+ }
}
void repositoryShow (ZebraHandle zh)
if (!(dict = dict_open (zh->reg->bfs, FMATCH_DICT, 50, 0, 0)))
{
- logf (LOG_FATAL, "dict_open fail of %s", FMATCH_DICT);
+ yaz_log (LOG_FATAL, "dict_open fail of %s", FMATCH_DICT);
return;
}
di = dirs_open (dict, src, rGroup->flagRw);
while ( (dst = dirs_read (di)) )
- logf (LOG_LOG, "%s", dst->path);
+ yaz_log (LOG_LOG, "%s", dst->path);
dirs_free (&di);
dict_close (dict);
}
struct stat sbuf;
char src[1024];
char dst[1024];
- int src_len;
+ int src_len, ret;
assert (path);
else
*src = '\0';
strcat (src, path);
- stat (src, &sbuf);
+ ret = zebra_file_stat (src, &sbuf, rGroup->followLinks);
strcpy (src, path);
src_len = strlen (src);
- if (S_ISREG(sbuf.st_mode))
+ if (ret == -1)
+ {
+ yaz_log (LOG_WARN|LOG_ERRNO, "Cannot access path %s", src);
+ }
+ else if (S_ISREG(sbuf.st_mode))
{
struct dirs_entry *e_dst;
di = dirs_fopen (dict, src);
}
else
{
- logf (LOG_WARN, "Ignoring path %s", src);
+ yaz_log (LOG_WARN, "Skipping path %s", src);
}
}
-
static void repositoryExtract (ZebraHandle zh,
int deleteFlag, struct recordGroup *rGroup,
const char *path)
{
struct stat sbuf;
char src[1024];
+ int ret;
assert (path);
else
*src = '\0';
strcat (src, path);
- stat (src, &sbuf);
+ ret = zebra_file_stat (src, &sbuf, rGroup->followLinks);
strcpy (src, path);
- if (S_ISREG(sbuf.st_mode))
+ if (ret == -1)
+ yaz_log (LOG_WARN|LOG_ERRNO, "Cannot access path %s", src);
+ else if (S_ISREG(sbuf.st_mode))
fileExtract (zh, NULL, src, rGroup, deleteFlag);
else if (S_ISDIR(sbuf.st_mode))
repositoryExtractR (zh, deleteFlag, src, rGroup, 0);
else
- logf (LOG_WARN, "Ignoring path %s", src);
+ yaz_log (LOG_WARN, "Skipping path %s", src);
}
static void repositoryExtractG (ZebraHandle zh,
if (!(dict = dict_open (zh->reg->bfs, FMATCH_DICT, 50,
rGroup->flagRw, 0)))
{
- logf (LOG_FATAL, "dict_open fail of %s", FMATCH_DICT);
+ yaz_log (LOG_FATAL, "dict_open fail of %s", FMATCH_DICT);
return ;
}
if (*rGroup->path == '\0' || !strcmp(rGroup->path, "-"))
void repositoryDelete (ZebraHandle zh)
{
- repositoryExtractG (zh, 1, &zh->rGroup);
+ struct recordGroup *rGroup = &zh->rGroup;
+ groupRes (zh, rGroup);
+ assert (rGroup->path);
+ repositoryExtractG (zh, 1, rGroup);
}