Bogus file copy for onlyIfModified=true

Aperta
#684 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@arturobernalg ci sta già lavorando.

Dal 19/11/2026.

  • #690 di @arturobernalg — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
65/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
java
Ambito
build-system

Direzione di ricerca

Start with AbstractWarPackagingTask.copyFile, which the issue identifies as comparing the source and destination modification times when onlyIfModified is true. Check the existing tests for this copy behavior and reproduce the case with files whose contents differ but modification times match. Done when changed content is copied despite equal timestamps and the relevant tests pass.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug
Affected version

3.5.1, possibly others

Bug description

While analysing a weird race-condition during WAR packaging, I might have discovered the responsible cause.

Symptom: On some builds, the WAR is badly packaged because modified files are not copied from the overlay to the target directory.
This seems to happen, when the overlay file has the same modify time as the target, although having been changed in the build process.

Analysis showed, that the modified overlay file is sometimes not copied, because the modification time is the same as the target file, although the file content differs.
Digging deeper revealed, that the modification timestamp has a granularity of 1 sec on the underlying filesystem (Apple HFS). So when the file modification and packaging actually run within a second, the file copy might be surpressed!

Responsible for that seems this method in AbstractWarPackagingTask:

protected boolean copyFile(
            WarPackagingContext context, File source, File destination, String targetFilename, boolean onlyIfModified)
            throws IOException {
        context.addResource(targetFilename);

        BasicFileAttributes readAttributes = Files.readAttributes(source.toPath(), BasicFileAttributes.class);
        if (onlyIfModified
                && destination.lastModified()
                        >= readAttributes.lastModifiedTime().toMillis()) {
            context.getLog().debug(" * " + targetFilename + " is up to date.");
            return false;
        } else {
...

Although the lastModifiedTime attribute is compared in millis, it effectively only compares in seconds, when the underlying FS hasn't that granularity. This even disregards a difference in file size.

Lingua principale
Java
Stelle
48
Fork
103
Merge medio
11h 20m
PR unite (30g)
15

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/maven-war-plugin

Tutte le issue di apache/maven-war-plugin

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.