apache / apache/maven-indexer

indexer-cli throws java.nio.file.FileAlreadyExistsException on re-run with same index dir

Open
#720 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
74
Forks
69
Avg merge
14h 8m
Merged PRs (30d)
6

Description

### Affected version

7.1.6

### Bug description

When running the CLI with:

```shell
java -jar indexer-cli-7.1.6-cli.jar \
--name clojars \
--type min \
--index ./index \
--destination ./repo/.index \
--repository ./repo \
--checksums \
--quiet \
--chunks \
--keep 50
```

It runs successfully on the first run (when `./index` is empty). On a subsequent run, it fails with:

```
java.io.IOException: Error scanning context clojars: java.nio.file.FileAlreadyExistsException: /tmp/clojars-tmp10757666929368582455/nexus-maven-repository-index-packer.properties
at org.apache.maven.index.DefaultNexusIndexer.scan(DefaultNexusIndexer.java:313)
at org.apache.maven.index.DefaultNexusIndexer.scan(DefaultNexusIndexer.java:258)
at org.apache.maven.index.cli.NexusIndexerCli.index(NexusIndexerCli.java:448)
at org.apache.maven.index.cli.NexusIndexerCli.execute(NexusIndexerCli.java:164)
at org.apache.maven.index.cli.NexusIndexerCli.main(NexusIndexerCli.java:116)
Caused by: java.nio.file.FileAlreadyExistsException: /tmp/clojars-tmp10757666929368582455/nexus-maven-repository-index-packer.properties
at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:94)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
at java.base/sun.nio.fs.UnixFileSystemProvider.newFileChannel(UnixFileSystemProvider.java:213)
at java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:244)
at java.base/java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:426)
at java.base/java.nio.file.Files.newOutputStream(Files.java:215)
at org.apache.lucene.store.FSDirectory$FSIndexOutput.(FSDirectory.java:394)
at org.apache.lucene.store.FSDirectory$FSIndexOutput.(FSDirectory.java:387)
at org.apache.lucene.store.FSDirectory.createOutput(FSDirectory.java:220)
at org.apache.lucene.store.Directory.copyFrom(Directory.java:181)
at org.apache.maven.index.context.IndexUtils.copyFile(IndexUtils.java:73)
at org.apache.maven.index.context.IndexUtils.copyFile(IndexUtils.java:63)
at org.apache.maven.index.context.IndexUtils.copyDirectory(IndexUtils.java:56)
at org.apache.maven.index.DefaultNexusIndexer.scan(DefaultNexusIndexer.java:291)
... 4 more
```

Removing `./index/nexus-maven-repository-index-packer.properties` allows the subsequent run to succeed.

I encountered this when attempting to upgrade clojars.org from `4.1.2` to `7.1.6`.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at NexusIndexerCli.index and DefaultNexusIndexer.scan, following the IndexUtils.copyDirectory call shown in the stack trace. Reproduce the command with an existing ./index and inspect how nexus-maven-repository-index-packer.properties is copied on the second run. Done means repeated runs with the same index directory complete without requiring manual file removal.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.