Mailing List Archive

r3720 - in trunk: c_src/KinoSearch perl/lib perl/lib/KinoSearch
Author: creamyg
Date: 2008-08-04 18:47:12 -0700 (Mon, 04 Aug 2008)
New Revision: 3720

Modified:
trunk/c_src/KinoSearch/InvIndex.bp
trunk/c_src/KinoSearch/InvIndex.c
trunk/perl/lib/KinoSearch.pm
trunk/perl/lib/KinoSearch/InvIndex.pm
Log:
Process InvIndex constructor args within C core.


Modified: trunk/c_src/KinoSearch/InvIndex.bp
===================================================================
--- trunk/c_src/KinoSearch/InvIndex.bp 2008-08-05 01:18:34 UTC (rev 3719)
+++ trunk/c_src/KinoSearch/InvIndex.bp 2008-08-05 01:47:12 UTC (rev 3720)
@@ -6,16 +6,16 @@
Folder *folder;

static InvIndex*
- init(InvIndex *self, Schema *schema, Folder *folder);
+ init(InvIndex *self, Schema *schema, Obj *folder);

static InvIndex*
- read(InvIndex *self, Schema *schema, Folder *folder);
+ read(InvIndex *self, Schema *schema, Obj *folder);

static InvIndex*
- open(InvIndex *self, Schema *schema, Folder *folder);
+ open(InvIndex *self, Schema *schema, Obj *folder);

static InvIndex*
- clobber(InvIndex *self, Schema *schema, Folder *folder);
+ clobber(InvIndex *self, Schema *schema, Obj *folder);

Schema*
Get_Schema(InvIndex *self);

Modified: trunk/c_src/KinoSearch/InvIndex.c
===================================================================
--- trunk/c_src/KinoSearch/InvIndex.c 2008-08-05 01:18:34 UTC (rev 3719)
+++ trunk/c_src/KinoSearch/InvIndex.c 2008-08-05 01:47:12 UTC (rev 3720)
@@ -14,22 +14,35 @@
init_invindex_files(InvIndex *self);

InvIndex*
-InvIndex_init(InvIndex *self, Schema *schema, Folder *folder)
+InvIndex_init(InvIndex *self, Schema *schema, Obj *folder)
{
self->schema = REFCOUNT_INC(schema);
- self->folder = REFCOUNT_INC(folder);
+ if (OBJ_IS_A(folder, FOLDER)) {
+ self->folder = (Folder*)REFCOUNT_INC(folder);
+ }
+ else if (OBJ_IS_A(folder, CHARBUF)) {
+ self->folder = (Folder*)FSFolder_new((CharBuf*)folder);
+ }
+ else {
+ CharBuf *mess = CB_newf("Invalid value for 'folder': '%o'", folder);
+ REFCOUNT_DEC(self);
+ Carp_do_confess(mess);
+ }
return self;
}

InvIndex*
-InvIndex_read(InvIndex *self, Schema *schema, Folder *folder)
+InvIndex_read(InvIndex *self, Schema *schema, Obj *folder)
{
self = InvIndex_init(self, schema, folder);

/* Ensure that an FSFolder's directory actually exists. */
- if (OBJ_IS_A(folder, FSFOLDER) && !DirManip_dir_ok(folder->path)) {
+ if ( OBJ_IS_A(self->folder, FSFOLDER)
+ && !DirManip_dir_ok(self->folder->path)
+ ) {
+ CharBuf *mess = CB_newf("'%o' isn't a directory", self->folder->path);
REFCOUNT_DEC(self);
- CONFESS("'%o' isn't a directory", folder->path);
+ Carp_do_confess(mess);
}

return self;
@@ -45,7 +58,7 @@
}

InvIndex*
-InvIndex_open(InvIndex *self, Schema *schema, Folder *folder)
+InvIndex_open(InvIndex *self, Schema *schema, Obj *folder)
{
CharBuf *most_recent_snap_file;

@@ -53,12 +66,14 @@
self = InvIndex_init(self, schema, folder);

/* If an FSFolder, confirm or create its index dir. */
- if (OBJ_IS_A(folder, FSFOLDER) && !DirManip_dir_ok(folder->path)) {
- DirManip_create_dir(folder->path);
+ if ( OBJ_IS_A(self->folder, FSFOLDER)
+ && !DirManip_dir_ok(self->folder->path)
+ ) {
+ DirManip_create_dir(self->folder->path);
}

/* Maybe initialize invindex files. */
- most_recent_snap_file = Folder_Latest_Snapshot_File(folder);
+ most_recent_snap_file = Folder_Latest_Snapshot_File(self->folder);
if (NULL == most_recent_snap_file) {
init_invindex_files(self);
}
@@ -68,7 +83,7 @@
}

InvIndex*
-InvIndex_clobber(InvIndex *self, Schema *schema, Folder *folder)
+InvIndex_clobber(InvIndex *self, Schema *schema, Obj *folder)
{
VArray *all_files;
VArray *kino_files;
@@ -78,17 +93,19 @@
self = InvIndex_init(self, schema, folder);

/* If an FSFolder, confirm or create its index dir. */
- if (OBJ_IS_A(folder, FSFOLDER) && !DirManip_dir_ok(folder->path)) {
- DirManip_create_dir(folder->path);
+ if ( OBJ_IS_A(self->folder, FSFOLDER)
+ && !DirManip_dir_ok(self->folder->path)
+ ) {
+ DirManip_create_dir(self->folder->path);
}

/* Initialize the invindex directory. */
- all_files = Folder_List_Real_Files(folder);
+ all_files = Folder_List_Real_Files(self->folder);
kino_files = IxFileNames_unused_files(all_files, NULL);
for (i = 0; i < kino_files->size; i++) {
/* Nuke existing index files. */
CharBuf *filename = (CharBuf*)VA_Fetch(kino_files, i);
- Folder_Delete_Real_File(folder, filename);
+ Folder_Delete_Real_File(self->folder, filename);
}
REFCOUNT_DEC(all_files);
REFCOUNT_DEC(kino_files);

Modified: trunk/perl/lib/KinoSearch/InvIndex.pm
===================================================================
--- trunk/perl/lib/KinoSearch/InvIndex.pm 2008-08-05 01:18:34 UTC (rev 3719)
+++ trunk/perl/lib/KinoSearch/InvIndex.pm 2008-08-05 01:47:12 UTC (rev 3720)
@@ -7,9 +7,8 @@
__AUTO_XS__

{ "KinoSearch::InvIndex" => {
- bind_methods => [ qw( get_schema get_folder ) ],
- make_constructors =>
- [qw( _new|init _read|read _open|open _clobber|clobber )],
+ bind_methods => [qw( get_schema get_folder )],
+ make_constructors => [qw( read|read open|open clobber|clobber )],
}
}


Modified: trunk/perl/lib/KinoSearch.pm
===================================================================
--- trunk/perl/lib/KinoSearch.pm 2008-08-05 01:18:34 UTC (rev 3719)
+++ trunk/perl/lib/KinoSearch.pm 2008-08-05 01:47:12 UTC (rev 3720)
@@ -196,33 +196,9 @@

{
package KinoSearch::InvIndex;
- use KinoSearch::Util::ToolSet qw( confess a_isa_b );
+ use KinoSearch::Util::ToolSet qw( confess );

sub new { confess("InvIndex's constructors are clobber, open, and read") }
-
- sub _process_args {
- my ( $either, %args ) = @_;
-
- # Confirm Schema.
- confess("Missing required parameter 'schema'")
- unless a_isa_b( $args{schema}, "KinoSearch::Schema" );
-
- # Confirm or create a Folder object.
- if ( !defined $args{folder} ) {
- confess("Missing required parameter 'folder'");
- }
- elsif ( !a_isa_b( $args{folder}, 'KinoSearch::Store::Folder' ) ) {
- $args{folder}
- = KinoSearch::Store::FSFolder->new( path => $args{folder} );
- }
-
- return ( $either, %args );
- }
-
- sub open { return _open( _process_args(@_) ) }
- sub read { return _read( _process_args(@_) ) }
- sub clobber { return _clobber( _process_args(@_) ) }
-
}

{


_______________________________________________
kinosearch-commits mailing list
kinosearch-commits@rectangular.com
http://www.rectangular.com/mailman/listinfo/kinosearch-commits