Bogus file copy for onlyIfModified=true

未关闭
#684 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@arturobernalg 已经在做这个了。

开始于 2026年11月19日。

  • #690 来自 @arturobernalg —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
65/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
java
领域
build-system

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Java
星标
48
派生
103
平均合并
11 小时 20 分钟
30 天内合并 PR
15

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/maven-war-plugin 的其他 Issue

查看 apache/maven-war-plugin 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。