Skip to content

Commit

Permalink
Merge pull request apache#7586 from mbien/fix-cannot-create-dir
Browse files Browse the repository at this point in the history
Clean old temporary local maven index cache dir before scan
  • Loading branch information
mbien authored Jul 16, 2024
2 parents 0d9ea57 + 76d9b45 commit 1b31400
Showing 1 changed file with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@
import org.codehaus.plexus.component.repository.ComponentDescriptor;
import org.codehaus.plexus.component.repository.ComponentRequirement;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.util.FileUtils;
import org.netbeans.api.annotations.common.CheckForNull;
import org.netbeans.api.annotations.common.NullAllowed;
import org.netbeans.modules.maven.embedder.EmbedderFactory;
Expand Down Expand Up @@ -613,7 +612,7 @@ private void indexLoadedRepo(final RepositoryInfo repo, boolean updateLocal) thr
try {
// Ensure no stale cache files are left
removeGroupCache(repo);
scan(indexingContext, null, repoListener, updateLocal);
scanLocalRepo(indexingContext, null, repoListener, updateLocal);
storeGroupCache(repo, indexingContext);
} finally {
repoListener.close();
Expand Down Expand Up @@ -796,34 +795,34 @@ public void shutdownAll() {
* @see DefaultScannerListener
* @see #artifactDiscovered(ArtifactContext, IndexingContext)
*/
private void scan(IndexingContext context, String fromPath, ArtifactScanningListener listener, boolean update) throws IOException {
private void scanLocalRepo(IndexingContext context, String fromPath, ArtifactScanningListener listener, boolean update) throws IOException {

File repositoryDirectory = context.getRepository();
if (repositoryDirectory == null) {
return; // nothing to scan
}

if (!repositoryDirectory.exists()) {
throw new IOException( "Repository directory " + repositoryDirectory + " does not exist" );
}

// always use cache directory when reindexing
File tmpDir = new File(Places.getCacheDirectory(), "tmp-" + context.getRepositoryId());
if (!tmpDir.mkdirs()) {
throw new IOException( "Cannot create temporary directory: " + tmpDir );
Path tmpDir = Places.getCacheDirectory().toPath().resolve("tmp-" + context.getRepositoryId());
if (Files.exists(tmpDir)) {
removeDir(tmpDir);
}
File tmpFile = new File(tmpDir, context.getId() + "-tmp"); // TODO: purpose of file?
Files.createDirectory(tmpDir);

IndexingContext tmpContext = null;
try {
FSDirectory directory = FSDirectory.open(tmpDir.toPath());
FSDirectory directory = FSDirectory.open(tmpDir);
if (update) {
IndexUtils.copyDirectory(context.getIndexDirectory(), directory);
}
tmpContext = new DefaultIndexingContext( context.getId() + "-tmp",
context.getRepositoryId(),
context.getRepository(),
tmpDir,
tmpDir.toFile(),
context.getRepositoryUrl(),
context.getIndexUpdateUrl(),
context.getIndexCreators(),
Expand All @@ -840,10 +839,7 @@ private void scan(IndexingContext context, String fromPath, ArtifactScanningList
if (tmpContext != null) {
tmpContext.close( true );
}
if (tmpFile.exists()) {
tmpFile.delete();
}
FileUtils.deleteDirectory(tmpDir);
removeDir(tmpDir);
}
}

Expand Down

0 comments on commit 1b31400

Please sign in to comment.