Mailing List Archive

r3854 - in trunk: c_src/KinoSearch/Index c_src/KinoSearch/Store perl/lib perl/lib/KinoSearch/Test perl/t
Author: creamyg
Date: 2008-09-09 17:01:34 -0700 (Tue, 09 Sep 2008)
New Revision: 3854

Modified:
trunk/c_src/KinoSearch/Index/PostingsWriter.c
trunk/c_src/KinoSearch/Store/FSFolder.c
trunk/perl/lib/KinoSearch.pm
trunk/perl/lib/KinoSearch/Test/TestUtils.pm
trunk/perl/t/051-fsfile.t
trunk/perl/t/213-segment_merging.t
Log:
Clean up file handling to please Windows. Add _O_BINARY flag at file-opening time. Close files explicitly more often; undef objects that are holding files open; stop worrying about directory permissions on test dir.

Modified: trunk/c_src/KinoSearch/Index/PostingsWriter.c
===================================================================
--- trunk/c_src/KinoSearch/Index/PostingsWriter.c 2008-09-09 23:02:02 UTC (rev 3853)
+++ trunk/c_src/KinoSearch/Index/PostingsWriter.c 2008-09-10 00:01:34 UTC (rev 3854)
@@ -466,6 +466,8 @@
LexWriter_Finish(self->lex_writer);

/* Clean up. */
+ InStream_Close(self->lex_instream);
+ InStream_Close(self->post_instream);
Folder_Delete_File(folder, self->lex_tempname);
Folder_Delete_File(folder, self->post_tempname);
REFCOUNT_DEC(metadata);

Modified: trunk/c_src/KinoSearch/Store/FSFolder.c
===================================================================
--- trunk/c_src/KinoSearch/Store/FSFolder.c 2008-09-09 23:02:02 UTC (rev 3853)
+++ trunk/c_src/KinoSearch/Store/FSFolder.c 2008-09-10 00:01:34 UTC (rev 3854)
@@ -37,16 +37,30 @@
Folder_destroy((Folder*)self);
}

+static INLINE int write_flags()
+{
+ int flags = O_CREAT | O_WRONLY | O_EXCL;
#ifdef O_LARGEFILE
-static const int write_flags
- = O_CREAT | O_WRONLY | O_EXCL | O_LARGEFILE;
-static const int read_flags = O_RDONLY | O_LARGEFILE;
-#else
-static const int write_flags
- = O_CREAT | O_WRONLY | O_EXCL;
-static const int read_flags = O_RDONLY;
+ flags |= O_LARGEFILE;
#endif
+#ifdef _O_BINARY
+ flags |= _O_BINARY;
+#endif
+ return flags;
+}

+static INLINE int read_flags()
+{
+ int flags = O_RDONLY;
+#ifdef O_LARGEFILE
+ flags |= O_LARGEFILE;
+#endif
+#ifdef _O_BINARY
+ flags |= _O_BINARY;
+#endif
+ return flags;
+}
+
OutStream*
FSFolder_open_outstream(FSFolder *self, const CharBuf *filename)
{
@@ -66,7 +80,7 @@
do_open_outstream(FSFolder *self, const CharBuf *filename)
{
CharBuf *path = full_path(self, filename);
- FSFileDes *file_des = FSFileDes_new(path, write_flags, 0666, "ab");
+ FSFileDes *file_des = FSFileDes_new(path, write_flags(), 0666, "ab");
OutStream *outstream = file_des == NULL
? NULL
: OutStream_new((FileDes*)file_des);
@@ -82,7 +96,7 @@
FSFolder_open_filedes(FSFolder *self, const CharBuf *filename)
{
CharBuf *path = full_path(self, filename);
- FSFileDes *file_des = FSFileDes_new(path, read_flags, 0600, "rb");
+ FSFileDes *file_des = FSFileDes_new(path, read_flags(), 0600, "rb");

REFCOUNT_DEC(path);


Modified: trunk/perl/lib/KinoSearch/Test/TestUtils.pm
===================================================================
--- trunk/perl/lib/KinoSearch/Test/TestUtils.pm 2008-09-09 23:02:02 UTC (rev 3853)
+++ trunk/perl/lib/KinoSearch/Test/TestUtils.pm 2008-09-10 00:01:34 UTC (rev 3854)
@@ -47,19 +47,13 @@
sub working_dir {$working_dir}

sub create_working_dir {
- if ( !-d $working_dir ) {
- mkdir( $working_dir, 0700 )
- or confess "Can't mkdir '$working_dir': $!";
- }
+ mkdir( $working_dir, 0700 ) or die "Can't mkdir '$working_dir': $!";
}

# Verify that this user owns the working dir, then zap it. Returns true upon
# success.
sub remove_working_dir {
- my $mode = ( stat $working_dir )[2];
return unless -d $working_dir;
- $mode &= 07777;
- return unless $mode == 0700;
rmtree $working_dir;
return 1;
}

Modified: trunk/perl/lib/KinoSearch.pm
===================================================================
--- trunk/perl/lib/KinoSearch.pm 2008-09-09 23:02:02 UTC (rev 3853)
+++ trunk/perl/lib/KinoSearch.pm 2008-09-10 00:01:34 UTC (rev 3854)
@@ -297,7 +297,7 @@
my ( $self, $filename ) = @_;
eval { $self->get_invindex->get_folder->delete_file($filename) };
# Catch delete file exception.
- if ( $@ and $@ !~ /Folder_delete_file/ ) { die($@) }
+ if ( $@ and $@ !~ /Folder_delete/ ) { die($@) }
}
}


Modified: trunk/perl/t/051-fsfile.t
===================================================================
--- trunk/perl/t/051-fsfile.t 2008-09-09 23:02:02 UTC (rev 3853)
+++ trunk/perl/t/051-fsfile.t 2008-09-10 00:01:34 UTC (rev 3854)
@@ -26,11 +26,13 @@
my $foo;

sub new_outstream {
+ undef $outstream;
unlink $filepath;
return $folder->open_outstream($filename);
}

sub new_instream {
+ undef $instream;
return $folder->open_instream($filename);
}

@@ -54,6 +56,7 @@

eval { my $blah; $instream->read_bytes( $blah, 2 ) };
like( $@, qr/EOF/, "reading past EOF throws an error" );
+undef $instream;

$outstream = new_outstream();
$outstream->print( 'a' x 1024 );

Modified: trunk/perl/t/213-segment_merging.t
===================================================================
--- trunk/perl/t/213-segment_merging.t 2008-09-09 23:02:02 UTC (rev 3853)
+++ trunk/perl/t/213-segment_merging.t 2008-09-10 00:01:34 UTC (rev 3854)
@@ -88,6 +88,8 @@
push @got, $hits->next->{content} for 1 .. $hits->total_hits;
is_deeply( \@got, \@correct,
"correct top scoring hit from merged invindex" );
+ undef $searcher;
+ undef $hits;

# Reopen invindex under BiggerSchema and add some content.
undef $invindexer;


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