From 0c9fdce49848132a12807f8dc9706b382274f1df Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 12 Apr 1996 07:02:21 +0000 Subject: [PATCH] File update of single files. --- index/dirs.c | 33 +++++++++++++++++++++++- index/index.h | 6 ++++- index/trav.c | 79 +++++++++++++++++++++++++++++++++++++++++++++------------ 3 files changed, 100 insertions(+), 18 deletions(-) diff --git a/index/dirs.c b/index/dirs.c index b26ff3d..a5f13c4 100644 --- a/index/dirs.c +++ b/index/dirs.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: dirs.c,v $ - * Revision 1.7 1996-03-21 14:50:09 adam + * Revision 1.8 1996-04-12 07:02:21 adam + * File update of single files. + * + * Revision 1.7 1996/03/21 14:50:09 adam * File update uses modify-time instead of change-time. * * Revision 1.6 1996/02/02 13:44:43 adam @@ -104,6 +107,34 @@ struct dirs_info *dirs_open (Dict dict, const char *rep) return p; } +struct dirs_info *dirs_fopen (Dict dict, const char *path) +{ + struct dirs_info *p; + struct dirs_entry *entry; + char *info; + + p = xmalloc (sizeof(*p)); + p->dict = dict; + *p->prefix = '\0'; + p->entries = xmalloc (sizeof(*p->entries)); + p->no_read = 0; + p->no_cur = 0; + p->no_max = 2; + + entry = p->entries; + info = dict_lookup (dict, path); + if (info && info[0] == sizeof(entry->sysno)+sizeof(entry->mtime)) + { + strcpy (entry->path, path); + entry->kind = dirs_file; + memcpy (&entry->sysno, info+1, sizeof(entry->sysno)); + memcpy (&entry->mtime, info+1+sizeof(entry->sysno), + sizeof(entry->mtime)); + p->no_cur++; + } + return p; +} + struct dirs_entry *dirs_read (struct dirs_info *p) { int before = 0, after = p->no_max+1; diff --git a/index/index.h b/index/index.h index e8750d2..5491d85 100644 --- a/index/index.h +++ b/index/index.h @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: index.h,v $ - * Revision 1.37 1996-03-26 16:01:13 adam + * Revision 1.38 1996-04-12 07:02:23 adam + * File update of single files. + * + * Revision 1.37 1996/03/26 16:01:13 adam * New setting lockPath: directory of various lock files. * * Revision 1.36 1996/03/21 14:50:09 adam @@ -176,6 +179,7 @@ struct recordGroup { struct dirs_info *dirs_open (Dict dict, const char *rep); +struct dirs_info *dirs_fopen (Dict dict, const char *path); struct dirs_entry *dirs_read (struct dirs_info *p); struct dirs_entry *dirs_last (struct dirs_info *p); void dirs_mkdir (struct dirs_info *p, const char *src, time_t mtime); diff --git a/index/trav.c b/index/trav.c index 55e38c5..36b72a7 100644 --- a/index/trav.c +++ b/index/trav.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: trav.c,v $ - * Revision 1.22 1996-04-09 06:50:50 adam + * Revision 1.23 1996-04-12 07:02:25 adam + * File update of single files. + * + * Revision 1.22 1996/04/09 06:50:50 adam * Bug fix: bad reference in function fileUpdateR. * * Revision 1.21 1996/03/22 15:34:18 quinn @@ -360,43 +363,87 @@ void repositoryShow (struct recordGroup *rGroup) dict_close (dict); } -void repositoryUpdate (struct recordGroup *rGroup) +static void fileUpdate (Dict dict, struct recordGroup *rGroup, + const char *path) { + struct dirs_info *di; + struct stat sbuf; char src[1024]; char dst[1024]; int src_len; - groupRes (rGroup); - if (rGroup->recordId && !strcmp (rGroup->recordId, "file")) + assert (path); + strcpy (src, path); + src_len = strlen (src); + + stat (src, &sbuf); + if (S_ISREG(sbuf.st_mode)) { - Dict dict; - struct dirs_info *di; + struct dirs_entry *e_dst; + di = dirs_fopen (dict, src); - if (!(dict = dict_open (FMATCH_DICT, 50, 1))) + logf (LOG_WARN, "Handle file %s", src); + e_dst = dirs_read (di); + if (e_dst) { - logf (LOG_FATAL, "dict_open fail of %s", FMATCH_DICT); - exit (1); + logf (LOG_WARN, "Update Handle file %s", src); + if (sbuf.st_mtime > e_dst->mtime) + if (fileExtract (&e_dst->sysno, src, rGroup, 0)) + dirs_add (di, src, e_dst->sysno, sbuf.st_mtime); } - assert (rGroup->path); - - strcpy (src, rGroup->path); - src_len = strlen (src); - + else + { + SYSNO sysno = 0; + logf (LOG_WARN, "New Handle file %s", src); + if (fileExtract (&sysno, src, rGroup, 0)) + dirs_add (di, src, sysno, sbuf.st_mtime); + } + dirs_free (&di); + } + else if (S_ISDIR(sbuf.st_mode)) + { if (src_len && src[src_len-1] != '/') { src[src_len] = '/'; src[++src_len] = '\0'; } - di = dirs_open (dict, src); - *dst = '\0'; fileUpdateR (di, dirs_read (di), src, dst, rGroup); dirs_free (&di); + } + else + { + logf (LOG_WARN, "Cannot handle file %s", src); + } +} + +void repositoryUpdate (struct recordGroup *rGroup) +{ + groupRes (rGroup); + assert (rGroup->path); + if (rGroup->recordId && !strcmp (rGroup->recordId, "file")) + { + Dict dict; + if (!(dict = dict_open (FMATCH_DICT, 50, 1))) + { + logf (LOG_FATAL, "dict_open fail of %s", FMATCH_DICT); + exit (1); + } + if (*rGroup->path == '\0' || !strcmp(rGroup->path, "-")) + { + char src[1024]; + while (scanf ("%s", src) == 1) + fileUpdate (dict, rGroup, src); + } + else + fileUpdate (dict, rGroup, rGroup->path); dict_close (dict); } else { + char src[1024]; + strcpy (src, rGroup->path); if (*src == '\0' || !strcmp (src, "-")) stdinExtractR (0, rGroup); -- 1.7.10.4