Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean old temporary local maven index cache dir before scan #7586

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading