Changed naming of some functions.
[idzebra-moved-to-github.git] / index / trav.c
index 4ac3629..4d087bd 100644 (file)
@@ -4,7 +4,30 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: trav.c,v $
- * Revision 1.12  1995-11-24 11:31:37  adam
+ * Revision 1.17  1996-02-12 18:45:17  adam
+ * Changed naming of some functions.
+ *
+ * Revision 1.16  1996/02/05  12:30:02  adam
+ * Logging reduced a bit.
+ * The remaining running time is estimated during register merge.
+ *
+ * Revision 1.15  1995/12/07  17:38:48  adam
+ * Work locking mechanisms for concurrent updates/commit.
+ *
+ * Revision 1.14  1995/12/06  12:41:26  adam
+ * New command 'stat' for the index program.
+ * Filenames can be read from stdin by specifying '-'.
+ * Bug fix/enhancement of the transformation from terms to regular
+ * expressons in the search engine.
+ *
+ * Revision 1.13  1995/11/28  09:09:46  adam
+ * Zebra config renamed.
+ * Use setting 'recordId' to identify record now.
+ * Bug fix in recindex.c: rec_release_blocks was invokeded even
+ * though the blocks were already released.
+ * File traversal properly deletes records when needed.
+ *
+ * Revision 1.12  1995/11/24  11:31:37  adam
  * Commands add & del read filenames from stdin if source directory is
  * empty.
  * Match criteria supports 'constant' strings.
@@ -74,6 +97,7 @@ static void repositoryExtractR (int deleteFlag, char *rep,
     e = dir_open (rep);
     if (!e)
         return;
+    logf (LOG_LOG, "Dir: %s", rep);
     if (rep[rep_len-1] != '/')
         rep[rep_len] = '/';
     else
@@ -97,24 +121,55 @@ static void repositoryExtractR (int deleteFlag, char *rep,
 
 static void stdinExtractR (int deleteFlag, struct recordGroup *rGroup)
 {
-    char tmppath[256];
+    char tmppath[1024];
 
+    logf (LOG_LOG, "stdinExtractR");
     while (scanf ("%s", tmppath) == 1)
         fileExtract (NULL, tmppath, rGroup, deleteFlag);
 }
 
-static void repositoryUpdateR (struct dirs_info *di, struct dirs_entry *dst,
+static void fileDeleteR (struct dirs_info *di, struct dirs_entry *dst,
+                              const char *base, char *src,
+                              struct recordGroup *rGroup)
+{
+    char tmppath[1024];
+    size_t src_len = strlen (src);
+
+    while (dst && !repComp (dst->path, src, src_len+1))
+    {
+        switch (dst->kind)
+        {
+        case dirs_file:
+            sprintf (tmppath, "%s%s", base, dst->path);
+            fileExtract (&dst->sysno, tmppath, rGroup, 1);
+             
+            strcpy (tmppath, dst->path);
+            dst = dirs_read (di); 
+            dirs_del (di, tmppath);
+            break;
+        case dirs_dir:
+            strcpy (tmppath, dst->path);
+            dst = dirs_read (di);
+            dirs_rmdir (di, tmppath);
+            break;
+        default:
+            dst = dirs_read (di);
+        }
+    }
+}
+
+static void fileUpdateR (struct dirs_info *di, struct dirs_entry *dst,
                                const char *base, char *src, 
                                struct recordGroup *rGroup)
 {
     struct dir_entry *e_src;
     int i_src = 0;
-    static char tmppath[256];
+    static char tmppath[1024];
     size_t src_len = strlen (src);
 
     sprintf (tmppath, "%s%s", base, src);
     e_src = dir_open (tmppath);
-
+    logf (LOG_LOG, "Dir: %s", tmppath);
 #if 1
     if (!dst || repComp (dst->path, src, src_len))
 #else
@@ -133,7 +188,8 @@ static void repositoryUpdateR (struct dirs_info *di, struct dirs_entry *dst,
     }
     else if (!e_src)
     {
-        /* delete tree dst */
+        strcpy (src, dst->path);
+        fileDeleteR (di, dst, base, src, rGroup);
         return;
     }
     else
@@ -178,12 +234,14 @@ static void repositoryUpdateR (struct dirs_info *di, struct dirs_entry *dst,
                 if (e_src[i_src].ctime > dst->ctime)
                 {
                     if (fileExtract (&dst->sysno, tmppath, rGroup, 0))
+                    {
                         dirs_add (di, src, dst->sysno, e_src[i_src].ctime);
+                    }
                 }
                 dst = dirs_read (di);
                 break;
             case dirs_dir:
-                repositoryUpdateR (di, dst, base, src, rGroup);
+                fileUpdateR (di, dst, base, src, rGroup);
                 dst = dirs_last (di);
                 logf (LOG_DEBUG, "last is %s", dst ? dst->path : "null");
                 break;
@@ -205,7 +263,7 @@ static void repositoryUpdateR (struct dirs_info *di, struct dirs_entry *dst,
                     dirs_add (di, src, sysno, e_src[i_src].ctime);            
                 break;
             case dirs_dir:
-                repositoryUpdateR (di, dst, base, src, rGroup);
+                fileUpdateR (di, dst, base, src, rGroup);
                 if (dst)
                     dst = dirs_last (di);
                 break;
@@ -214,50 +272,81 @@ static void repositoryUpdateR (struct dirs_info *di, struct dirs_entry *dst,
         }
         else  /* sd < 0 */
         {
-            assert (0);
+            strcpy (src, dst->path);
+            sprintf (tmppath, "%s%s", base, dst->path);
+
+            switch (dst->kind)
+            {
+            case dirs_file:
+                fileExtract (&dst->sysno, tmppath, rGroup, 1);
+                dirs_del (di, dst->path);
+                dst = dirs_read (di);
+                break;
+            case dirs_dir:
+                fileDeleteR (di, dst, base, src, rGroup);
+                dst = dirs_last (di);
+            }
         }
     }
     dir_free (&e_src);
 }
 
-void repositoryUpdate (struct recordGroup *rGroup)
+static void groupRes (struct recordGroup *rGroup)
 {
-    struct dirs_info *di;
-    char src[256];
-    Dict dict;
+    char resStr[256];
+    char gPrefix[256];
 
-    dict = dict_open ("repdict", 40, 1);
-
-    assert (rGroup->path);
-    di = dirs_open (dict, rGroup->path);
-    strcpy (src, "");
-    repositoryUpdateR (di, dirs_read (di), rGroup->path, src, rGroup);
-    dirs_free (&di);
+    if (!rGroup->groupName || !*rGroup->groupName)
+        *gPrefix = '\0';
+    else
+        sprintf (gPrefix, "%s.", rGroup->groupName);
 
-    dict_close (dict);
+    sprintf (resStr, "%srecordId", gPrefix);
+    rGroup->recordId = res_get (common_resource, resStr);
 }
 
-void repositoryDelete (struct recordGroup *rGroup)
+void repositoryUpdate (struct recordGroup *rGroup)
 {
     char src[256];
 
-    assert (rGroup->path);
-    strcpy (src, rGroup->path);
-    if (*src == '\0')
-       stdinExtractR (1, rGroup);
-    else
-       repositoryExtractR (1, src, rGroup);
+    groupRes (rGroup);
+    if (rGroup->recordId && !strcmp (rGroup->recordId, "file"))
+    {
+        Dict dict;
+        struct dirs_info *di;
+
+        if (!(dict = dict_open (FMATCH_DICT, 50, 1)))
+        {
+            logf (LOG_FATAL, "dict_open fail of %s", FMATCH_DICT);
+            exit (1);
+        }
+        assert (rGroup->path);
+        di = dirs_open (dict, rGroup->path);
+        strcpy (src, "");
+        fileUpdateR (di, dirs_read (di), rGroup->path, src, rGroup);
+        dirs_free (&di);
+        dict_close (dict);
+    }
+    else 
+    {
+        strcpy (src, rGroup->path);
+        if (*src == '\0' || !strcmp (src, "-"))
+            stdinExtractR (0, rGroup);
+        else
+            repositoryExtractR (0, src, rGroup);
+    }
 }
 
-void repositoryAdd (struct recordGroup *rGroup)
+void repositoryDelete (struct recordGroup *rGroup)
 {
     char src[256];
 
     assert (rGroup->path);
+    groupRes (rGroup);
     strcpy (src, rGroup->path);
-    if (*src == '\0')
-       stdinExtractR (0, rGroup);
+    if (*src == '\0' || !strcmp(src, "-"))
+       stdinExtractR (1, rGroup);
     else
-       repositoryExtractR (0, src, rGroup);
+       repositoryExtractR (1, src, rGroup);
 }