Skip to content

Commit

Permalink
[MINDEXER-140] Fix double invocation of DefaultIndexingContext.setInd…
Browse files Browse the repository at this point in the history
…exDirectoryFile (#178)

DefaultIndexingContext invokes method setIndexDirectoryFile two times (if indexDirectory set): once with null and once with given indexDirectory.

In first case, ID is used to create temp directory, just to have 2nd invocation use passed in directory (and leave temp directory created in 1st invocation alone).

This bug, in relation to commit 019edb7 broke Spring examples, as it seems Spring example contained a typo since beginning: it uses "/" (slash) in context ID.

Files.createTempDirectory fails if prefix contains path separator.

---

https://issues.apache.org/jira/browse/MINDEXER-140
  • Loading branch information
cstamas authored Feb 14, 2022
1 parent 71a4fb2 commit 28fd31a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ private DefaultIndexingContext( String id,
String repositoryUrl, String indexUpdateUrl,
List<? extends IndexCreator> indexCreators, Directory indexDirectory,
TrackingLockFactory lockFactory,
boolean reclaimIndex )
boolean reclaimIndex,
File indexDirectoryFile )
throws ExistingLuceneIndexMismatchException, IOException
{

Expand Down Expand Up @@ -164,7 +165,7 @@ private DefaultIndexingContext( String id,

prepareIndex( reclaimIndex );

setIndexDirectoryFile( null );
setIndexDirectoryFile( indexDirectoryFile );
}

private DefaultIndexingContext( String id, String repositoryId, File repository, File indexDirectoryFile,
Expand All @@ -173,9 +174,8 @@ private DefaultIndexingContext( String id, String repositoryId, File repository,
throws IOException, ExistingLuceneIndexMismatchException
{
this( id, repositoryId, repository, repositoryUrl, indexUpdateUrl, indexCreators,
FSDirectory.open( indexDirectoryFile.toPath(), lockFactory ), lockFactory, reclaimIndex );

setIndexDirectoryFile( indexDirectoryFile );
FSDirectory.open( indexDirectoryFile.toPath(), lockFactory ), lockFactory, reclaimIndex,
indexDirectoryFile );
}

public DefaultIndexingContext( String id, String repositoryId, File repository, File indexDirectoryFile,
Expand All @@ -194,12 +194,9 @@ public DefaultIndexingContext( String id, String repositoryId, File repository,
throws IOException, ExistingLuceneIndexMismatchException
{
this( id, repositoryId, repository, repositoryUrl, indexUpdateUrl, indexCreators, indexDirectory, null,
reclaimIndex ); // Lock factory already installed - pass null

if ( indexDirectory instanceof FSDirectory )
{
setIndexDirectoryFile( ( (FSDirectory) indexDirectory ).getDirectory().toFile() );
}
reclaimIndex, indexDirectory instanceof FSDirectory
? ( (FSDirectory) indexDirectory ).getDirectory().toFile() : null
); // Lock factory already installed - pass null
}

public Directory getIndexDirectory()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public RepositoryIndexer createRepositoryIndexer( String repositoryId, File repo
private IndexingContext createIndexingContext( String repositoryId, File repositoryBasedir, File indexDir )
throws IOException
{
return getIndexer().createIndexingContext( repositoryId + "/ctx", repositoryId, repositoryBasedir, indexDir,
return getIndexer().createIndexingContext( repositoryId + "-ctx", repositoryId, repositoryBasedir, indexDir,
null, null, true,
// if context should be searched in non-targeted mode.
true, // if indexDirectory is known to contain (or should contain)
Expand Down

0 comments on commit 28fd31a

Please sign in to comment.