lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject svn commit: r885650 - in /lucene/lucy/trunk/core/Lucy/Util: IndexFileNames.bp IndexFileNames.c
Date Tue, 01 Dec 2009 02:01:23 GMT
Author: marvin
Date: Tue Dec  1 02:01:17 2009
New Revision: 885650

URL: http://svn.apache.org/viewvc?rev=885650&view=rev
Log:
Commit LUCY-78, adding IxFileNames_latest_snapshot() for detecting the most
recent snapshot_NNN.json file within a Folder.

Modified:
    lucene/lucy/trunk/core/Lucy/Util/IndexFileNames.bp
    lucene/lucy/trunk/core/Lucy/Util/IndexFileNames.c

Modified: lucene/lucy/trunk/core/Lucy/Util/IndexFileNames.bp
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Util/IndexFileNames.bp?rev=885650&r1=885649&r2=885650&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Util/IndexFileNames.bp (original)
+++ lucene/lucy/trunk/core/Lucy/Util/IndexFileNames.bp Tue Dec  1 02:01:17 2009
@@ -13,6 +13,12 @@
     inert i32_t
     extract_gen(const CharBuf *name);
 
+    /** Return the name of the latest generation snapshot file in the Folder,
+     * or NULL if no such file exists.
+     */
+    inert incremented CharBuf*
+    latest_snapshot(Folder *folder);
+
     /** Split the <code>path</code> on '/' and assign the last component to
      * <code>target</code>, which will remain valid only as long as
      * <code>path</code> is unmodified.  Trailing slashes will be stripped. 


Modified: lucene/lucy/trunk/core/Lucy/Util/IndexFileNames.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Util/IndexFileNames.c?rev=885650&r1=885649&r2=885650&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Util/IndexFileNames.c (original)
+++ lucene/lucy/trunk/core/Lucy/Util/IndexFileNames.c Tue Dec  1 02:01:17 2009
@@ -2,8 +2,37 @@
 #include "Lucy/Util/ToolSet.h"
 
 #include "Lucy/Util/IndexFileNames.h"
+#include "Lucy/Store/DirHandle.h"
+#include "Lucy/Store/Folder.h"
 #include "Lucy/Util/StringHelper.h"
 
+CharBuf*
+IxFileNames_latest_snapshot(Folder *folder)
+{
+    DirHandle *dh = Folder_Open_Dir(folder, NULL);
+    CharBuf   *entry = dh ? DH_Get_Entry(dh) : NULL;
+    CharBuf   *retval   = NULL;
+    i32_t      latest_gen = 0;
+
+    if (!dh) { RETHROW(INCREF(Err_get_error())); }
+
+    while (DH_Next(dh)) {
+        if (   CB_Starts_With_Str(entry, "snapshot_", 9)
+            && CB_Ends_With_Str(entry, ".json", 5)
+        ) {
+            i32_t gen = IxFileNames_extract_gen(entry);
+            if (gen > latest_gen) {
+                latest_gen = gen;
+                if (!retval) retval = CB_Clone(entry);
+                else CB_Mimic(retval, (Obj*)entry);
+            }
+        }
+    }
+
+    DECREF(dh);
+    return retval;
+}
+
 i32_t
 IxFileNames_extract_gen(const CharBuf *name)
 {



Mime
View raw message