You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2009/12/01 03:01:23 UTC
svn commit: r885650 - in /lucene/lucy/trunk/core/Lucy/Util:
IndexFileNames.bp IndexFileNames.c
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)
{