Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Merged in trunk changes.
Browse files Browse the repository at this point in the history
git-svn-id: file:///opt/svn/repositories/sonatype.org/nexus/branches/nexus-1.2.x/nexus@2650 2aa8b3fc-8ebb-4439-a84f-95066eaea8ab
  • Loading branch information
cstamas committed Dec 11, 2008
1 parent 334fdec commit 38571ab
Showing 1 changed file with 115 additions and 106 deletions.
Expand Up @@ -219,7 +219,7 @@ public void updateRepositoryIndexContext( String repositoryId )

File repoRoot = getRepositoryLocalStorageAsFile( repository );

// get context for repository
// get context for repository, check is change needed
IndexingContext ctx = nexusIndexer.getIndexingContexts().get( getLocalContextId( repository.getId() ) );

if ( !ctx.getRepository().getAbsolutePath().equals( repoRoot.getAbsolutePath() )
Expand Down Expand Up @@ -300,12 +300,6 @@ public void addRepositoryGroupIndexContext( String repositoryGroupId )
// it gets only published

ctxMerged.setSearchable( false );

// if ( ctxMerged.getTimestamp() == null )
// {
// // it is probably new or first start
// ctxMerged.updateTimestamp();
// }
}

public void removeRepositoryGroupIndexContext( String repositoryGroupId, boolean deleteFiles )
Expand Down Expand Up @@ -341,6 +335,8 @@ public void setRepositoryIndexContextSearchable( String repositoryId, boolean se
{
IndexingContext ctx = nexusIndexer.getIndexingContexts().get( getLocalContextId( repositoryId ) );

IndexingContext rctx = nexusIndexer.getIndexingContexts().get( getRemoteContextId( repositoryId ) );

if ( !ctx.isSearchable() && searchable )
{
// we have a !searchable -> searchable transition, reindex it
Expand All @@ -353,10 +349,7 @@ public void setRepositoryIndexContextSearchable( String repositoryId, boolean se

ctx.setSearchable( searchable );

if ( nexusIndexer.getIndexingContexts().containsKey( getRemoteContextId( repositoryId ) ) )
{
nexusIndexer.getIndexingContexts().get( getRemoteContextId( repositoryId ) ).setSearchable( searchable );
}
rctx.setSearchable( searchable );
}

/**
Expand Down Expand Up @@ -741,11 +734,7 @@ protected void reindexRepository( Repository repository )

context.replace( tmpContext.getIndexDirectory() );

// only proxies have remote indexes
if ( RepositoryType.PROXY.equals( repository.getRepositoryType() ) )
{
updateIndexForRemoteRepository( repository );
}
updateIndexForRemoteRepository( repository );

mergeRepositoryGroupIndexWithMember( repository );
}
Expand Down Expand Up @@ -832,151 +821,171 @@ protected void purgeRepositoryGroupIndex( String repositoryGroupId )
private boolean updateIndexForRemoteRepository( Repository repository )
throws IOException
{
boolean shouldDownloadRemoteIndex = false;

try
{
CRepository repoModel = nexusConfiguration.readRepository( repository.getId() );

shouldDownloadRemoteIndex = repoModel.isDownloadRemoteIndexes();
}
catch ( NoSuchRepositoryException e )
if ( RepositoryType.PROXY.equals( repository.getRepositoryType() ) )
{
// TODO: heee?
}
boolean shouldDownloadRemoteIndex = false;

boolean hasRemoteIndex = false;

if ( shouldDownloadRemoteIndex )
{
try
{
getLogger().info( "Trying to get remote index for repository " + repository.getId() );
CRepository repoModel = nexusConfiguration.readRepository( repository.getId() );

updateRemoteIndex( repository );
shouldDownloadRemoteIndex = repoModel.isDownloadRemoteIndexes();
}
catch ( NoSuchRepositoryException e )
{
// TODO: heee?
}

getLogger().info( "Remote indexes updated successfully for repository " + repository.getId() );
boolean hasRemoteIndex = false;

hasRemoteIndex = true;
if ( shouldDownloadRemoteIndex )
{
try
{
getLogger().info( "Trying to get remote index for repository " + repository.getId() );

hasRemoteIndex = updateRemoteIndex( repository );

if ( hasRemoteIndex )
{
getLogger().info( "Remote indexes updated successfully for repository " + repository.getId() );
}
else
{
getLogger().info(
"Remote indexes unchanged (no update needed) for repository " + repository.getId() );
}
}
catch ( Exception e )
{
getLogger().warn( "Cannot fetch remote index:", e );
}
}
catch ( Exception e )
else
{
getLogger().warn( "Cannot fetch remote index:", e );
// make empty the remote context
IndexingContext context = nexusIndexer.getIndexingContexts().get(
getRemoteContextId( repository.getId() ) );

context.purge();

// XXX remove obsolete files, should remove all index fragments
// deleteItem( repository, ctx, zipUid );
// deleteItem( repository, ctx, chunkUid ) ;
}

return hasRemoteIndex;
}
else
{
// make empty the remote context
IndexingContext context = nexusIndexer.getIndexingContexts().get( getRemoteContextId( repository.getId() ) );

context.purge();

// XXX remove obsolete files, should remove all index fragments
// deleteItem( repository, ctx, zipUid );
// deleteItem( repository, ctx, chunkUid ) ;
return false;
}

return hasRemoteIndex;
}

private boolean updateRemoteIndex( Repository repository )
throws IOException,
RepositoryNotAvailableException,
ItemNotFoundException
{
// this will force redownload
// XXX should only force downloading of the .properties file
repository.clearCaches( "/.index" );
if ( RepositoryType.PROXY.equals( repository.getRepositoryType() ) )
{
// this will force redownload
// XXX should only force downloading of the .properties file
repository.clearCaches( "/.index" );

IndexingContext context = null;
IndexingContext context = null;

try
{
context = getRepositoryRemoteIndexContext( repository.getId() );
}
catch ( NoSuchRepositoryException e )
{
// will not happen
}
try
{
context = getRepositoryRemoteIndexContext( repository.getId() );
}
catch ( NoSuchRepositoryException e )
{
// will not happen
}

Date contextTimestamp = context.getTimestamp();
Date contextTimestamp = context.getTimestamp();

RepositoryItemUid propsUid = repository.createUid( //
"/.index/" + IndexingContext.INDEX_FILE + ".properties" );
RepositoryItemUid propsUid = repository.createUid( //
"/.index/" + IndexingContext.INDEX_FILE + ".properties" );

Map<String, Object> ctx = new HashMap<String, Object>();
Map<String, Object> ctx = new HashMap<String, Object>();

StorageFileItem propItem = retrieveItem( repository, ctx, propsUid );
StorageFileItem propItem = retrieveItem( repository, ctx, propsUid );

File tmpdir = null;
File tmpdir = null;

FSDirectory directory = null;
FSDirectory directory = null;

try
{
if ( contextTimestamp != null )
try
{
Properties properties = loadProperties( propItem );
if ( contextTimestamp != null )
{
Properties properties = loadProperties( propItem );

Date updateTimestamp = indexUpdater.getTimestamp( properties, IndexingContext.INDEX_TIMESTAMP );
Date updateTimestamp = indexUpdater.getTimestamp( properties, IndexingContext.INDEX_TIMESTAMP );

if ( updateTimestamp != null && contextTimestamp.after( updateTimestamp ) )
{
return true; // index is up to date
}
if ( updateTimestamp != null && contextTimestamp.after( updateTimestamp ) )
{
return false; // index is up to date
}

String chunkName = indexUpdater.getUpdateChunkName( contextTimestamp, properties );
String chunkName = indexUpdater.getUpdateChunkName( contextTimestamp, properties );

if ( chunkName != null )
{
// download update index chunk
RepositoryItemUid zipUid = repository.createUid( "/.index/" + chunkName );
if ( chunkName != null )
{
// download update index chunk
RepositoryItemUid zipUid = repository.createUid( "/.index/" + chunkName );

StorageFileItem chunkItem = retrieveItem( repository, ctx, zipUid );
StorageFileItem chunkItem = retrieveItem( repository, ctx, zipUid );

tmpdir = createTmpDir();
tmpdir = createTmpDir();

directory = unpackIndex( chunkItem, repository, tmpdir );
directory = unpackIndex( chunkItem, repository, tmpdir );

context.merge( directory );
context.merge( directory );

return true;
return true;
}
}
}

// download full index
RepositoryItemUid zipUid = //
repository.createUid( "/.index/" + IndexingContext.INDEX_FILE + ".zip" );
// download full index
RepositoryItemUid zipUid = repository.createUid( "/.index/" + IndexingContext.INDEX_FILE + ".zip" );

StorageFileItem zipItem = retrieveItem( repository, ctx, zipUid );
StorageFileItem zipItem = retrieveItem( repository, ctx, zipUid );

tmpdir = createTmpDir();
tmpdir = createTmpDir();

directory = unpackIndex( zipItem, repository, tmpdir );
directory = unpackIndex( zipItem, repository, tmpdir );

context.replace( directory );
context.replace( directory );

return true;
}
finally
{
if ( directory != null )
{
directory.close();
return true;
}

if ( tmpdir != null )
finally
{
try
if ( directory != null )
{
FileUtils.deleteDirectory( tmpdir );
directory.close();
}
catch ( IOException ex )

if ( tmpdir != null )
{
// ignore
try
{
FileUtils.deleteDirectory( tmpdir );
}
catch ( IOException ex )
{
// ignore
}
}
}
}
else
{
return false;
}
}

private Properties loadProperties( StorageFileItem item )
Expand Down

0 comments on commit 38571ab

Please sign in to comment.