From 4a617d48ef8d8516c83bf49fac1206b580ba537e Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 3 Sep 2002 11:44:54 +0000 Subject: [PATCH] Follow of symlinks can be controlled with config followLinks and option -L --- CHANGELOG | 4 ++++ index/dir.c | 19 ++++++++++++++----- index/index.h | 8 ++++++-- index/main.c | 8 ++++++-- index/trav.c | 24 +++++++++++++++--------- index/zebraapi.h | 25 +++++++++++++------------ 6 files changed, 58 insertions(+), 30 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 7cfa41f..8f2e6a6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,10 @@ --- 1.3.2 2002/MM/DD +New config setting, followLinks, that controls whether update or files +should follow symbolic. Set it to 1 (for enable) or 0 (to disable). +By default symbolic links are followed. + Fix MARC transfer . MARC fields had wrong data for multiple fields. XML record reader moved from YAZ to Zebra, to make YAZ less diff --git a/index/dir.c b/index/dir.c index db679d0..420c4f3 100644 --- a/index/dir.c +++ b/index/dir.c @@ -1,4 +1,4 @@ -/* $Id: dir.c,v 1.23 2002-08-02 19:26:55 adam Exp $ +/* $Id: dir.c,v 1.24 2002-09-03 11:44:54 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -28,14 +28,23 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #endif #include -#include #include #include #include #include "index.h" -struct dir_entry *dir_open (const char *rep, const char *base) + +int zebra_file_stat (const char *file_name, struct stat *buf, + int follow_links) +{ + if (follow_links) + return stat(file_name, buf); + return lstat(file_name, buf); +} + +struct dir_entry *dir_open (const char *rep, const char *base, + int follow_links) { DIR *dir; char path[1024]; @@ -91,10 +100,10 @@ struct dir_entry *dir_open (const char *rep, const char *base) strcpy (full_rep, base); strcat (full_rep, "/"); strcat (full_rep, path); - stat (full_rep, &finfo); + zebra_file_stat (full_rep, &finfo, follow_links); } else - stat (path, &finfo); + zebra_file_stat (path, &finfo, follow_links); switch (finfo.st_mode & S_IFMT) { case S_IFREG: diff --git a/index/index.h b/index/index.h index ccb2714..7d6e2b9 100644 --- a/index/index.h +++ b/index/index.h @@ -1,4 +1,4 @@ -/* $Id: index.h,v 1.86 2002-08-28 19:52:29 adam Exp $ +/* $Id: index.h,v 1.87 2002-09-03 11:44:54 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -34,6 +34,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #if HAVE_SYS_TIMES_H #include #endif +#include #include #include @@ -92,7 +93,8 @@ void dirs_add (struct dirs_info *p, const char *src, int sysno, time_t mtime); void dirs_del (struct dirs_info *p, const char *src); void dirs_free (struct dirs_info **pp); -struct dir_entry *dir_open (const char *rep, const char *base); +struct dir_entry *dir_open (const char *rep, const char *base, + int follow_links); void dir_sort (struct dir_entry *e); void dir_free (struct dir_entry **e_p); @@ -435,6 +437,8 @@ int fileExtract (ZebraHandle zh, SYSNO *sysno, const char *fname, int zebra_begin_read (ZebraHandle zh); void zebra_end_read (ZebraHandle zh); +int zebra_file_stat (const char *file_name, struct stat *buf, + int follow_links); YAZ_END_CDECL diff --git a/index/main.c b/index/main.c index 02101ab..91e3556 100644 --- a/index/main.c +++ b/index/main.c @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.95 2002-08-29 08:47:08 adam Exp $ +/* $Id: main.c,v 1.96 2002-09-03 11:44:54 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -84,6 +84,7 @@ int main (int argc, char **argv) rGroupDef.databaseNamePath = 0; rGroupDef.explainDatabase = 0; rGroupDef.fileVerboseLimit = 100000; + rGroupDef.followLinks = -1; prog = *argv; if (argc < 2) @@ -105,12 +106,13 @@ int main (int argc, char **argv) " -s Show analysis on stdout, but do no work.\n" " -v Set logging to .\n" " -l Write log to .\n" + " -L Don't follow symbolic links.\n" " -f Display information for the first records.\n" " -V Show version.\n", *argv ); exit (1); } - while ((ret = options ("sVt:c:g:d:m:v:nf:l:" + while ((ret = options ("sVt:c:g:d:m:v:nf:l:L" , argv, argc, &arg)) != -2) { if (ret == 0) @@ -246,6 +248,8 @@ int main (int argc, char **argv) rGroupDef.recordType = arg; else if (ret == 'n') disableCommit = 1; + else if (ret == 'L') + rGroupDef.followLinks = 0; else logf (LOG_WARN, "unknown option '-%s'", arg); } diff --git a/index/trav.c b/index/trav.c index 1143d1e..267fedf 100644 --- a/index/trav.c +++ b/index/trav.c @@ -1,4 +1,4 @@ -/* $Id: trav.c,v 1.40 2002-08-02 19:26:55 adam Exp $ +/* $Id: trav.c,v 1.41 2002-09-03 11:44:54 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -20,13 +20,9 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - - - #include #include #include -#include #ifdef WIN32 #include #define S_ISREG(x) (x & _S_IFREG) @@ -55,7 +51,7 @@ static void repositoryExtractR (ZebraHandle zh, int deleteFlag, char *rep, 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); @@ -130,7 +126,7 @@ static void fileUpdateR (ZebraHandle zh, size_t src_len = strlen (src); sprintf (tmppath, "%s%s", base, src); - e_src = dir_open (tmppath, zh->path_reg); + e_src = dir_open (tmppath, zh->path_reg, rGroup->followLinks); logf (LOG_LOG, "dir %s", tmppath); #if 0 @@ -276,6 +272,16 @@ static void groupRes (ZebraHandle zh, struct recordGroup *rGroup) 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) @@ -332,7 +338,7 @@ static void fileUpdate (ZebraHandle zh, else *src = '\0'; strcat (src, path); - stat (src, &sbuf); + zebra_file_stat (src, &sbuf, rGroup->followLinks); strcpy (src, path); src_len = strlen (src); @@ -393,7 +399,7 @@ static void repositoryExtract (ZebraHandle zh, else *src = '\0'; strcat (src, path); - stat (src, &sbuf); + zebra_file_stat (src, &sbuf, rGroup->followLinks); strcpy (src, path); diff --git a/index/zebraapi.h b/index/zebraapi.h index e59018e..5d073fa 100644 --- a/index/zebraapi.h +++ b/index/zebraapi.h @@ -1,4 +1,4 @@ -/* $Id: zebraapi.h,v 1.19 2002-08-02 19:26:56 adam Exp $ +/* $Id: zebraapi.h,v 1.20 2002-09-03 11:44:54 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -33,17 +33,18 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA YAZ_BEGIN_CDECL struct recordGroup { - char *groupName; - char *databaseName; - char *path; - char *recordId; - char *recordType; - int flagStoreData; - int flagStoreKeys; - int flagRw; - int fileVerboseLimit; - int databaseNamePath; - int explainDatabase; + char *groupName; + char *databaseName; + char *path; + char *recordId; + char *recordType; + int flagStoreData; + int flagStoreKeys; + int flagRw; + int fileVerboseLimit; + int databaseNamePath; + int explainDatabase; + int followLinks; }; /* Retrieval Record Descriptor */ -- 1.7.10.4