This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch fix-build
in repository https://gitbox.apache.org/repos/asf/maven-gpg-plugin.git


The following commit(s) were added to refs/heads/fix-build by this push:
     new 931d16e  Fix #322: Convert Windows drive paths to MinGW format for GPG
931d16e is described below

commit 931d16e2c3d565ee5eea92c5ecd7821e354570f2
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Tue Jun 30 01:20:35 2026 +0200

    Fix #322: Convert Windows drive paths to MinGW format for GPG
    
    When GPG receives a Windows path with drive letter (e.g., D:/path), it 
incorrectly treats it as a relative path and prepends the current working 
directory. This causes errors like:
    
      gpg: keyblock resource '/d/a/b/c/D:/a/b/c/pubring.kbx': No such file or 
directory
    
    The fix introduces toMinGWPath() which converts Windows drive paths to 
MinGW format:
      - D:/a/b/c → /d/a/b/c
    
    Applied to homedir, output, and input file arguments. Combined with 
existing MSYS_NO_PATHCONV=1, this prevents path conversion errors on Windows.
---
 .../java/org/apache/maven/plugins/gpg/GpgSigner.java | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/maven/plugins/gpg/GpgSigner.java 
b/src/main/java/org/apache/maven/plugins/gpg/GpgSigner.java
index d3955ec..7e54e39 100644
--- a/src/main/java/org/apache/maven/plugins/gpg/GpgSigner.java
+++ b/src/main/java/org/apache/maven/plugins/gpg/GpgSigner.java
@@ -50,6 +50,20 @@ public class GpgSigner extends AbstractGpgSigner {
         return keyname != null ? keyname : "default";
     }
 
+    /**
+     * Converts a Windows absolute path to MinGW path format for GPG on 
Windows.
+     * For example, converts "D:/a/b/c" to "/d/a/b/c".
+     * This prevents MSYS2/GPG from incorrectly prepending the current working 
directory.
+     */
+    private String toMinGWPath(String path) {
+        String forwardPath = path.replace('\\', '/');
+        if (Os.isFamily(Os.FAMILY_WINDOWS) && forwardPath.length() >= 2 && 
forwardPath.charAt(1) == ':') {
+            char driveLetter = Character.toLowerCase(forwardPath.charAt(0));
+            return "/" + driveLetter + forwardPath.substring(2);
+        }
+        return forwardPath;
+    }
+
     /**
      * {@inheritDoc}
      */
@@ -86,7 +100,7 @@ public class GpgSigner extends AbstractGpgSigner {
 
         if (homeDir != null) {
             cmd.createArg().setValue("--homedir");
-            cmd.createArg().setValue(homeDir.getAbsolutePath().replace('\\', 
'/'));
+            cmd.createArg().setValue(toMinGWPath(homeDir.getAbsolutePath()));
         }
 
         if (gpgVersion.isBefore(GpgVersion.parse("2.1"))) {
@@ -178,9 +192,9 @@ public class GpgSigner extends AbstractGpgSigner {
         }
 
         cmd.createArg().setValue("--output");
-        cmd.createArg().setValue(signature.getAbsolutePath().replace('\\', 
'/'));
+        cmd.createArg().setValue(toMinGWPath(signature.getAbsolutePath()));
 
-        cmd.createArg().setValue(file.getAbsolutePath().replace('\\', '/'));
+        cmd.createArg().setValue(toMinGWPath(file.getAbsolutePath()));
 
         // 
----------------------------------------------------------------------------
         // Execute the command line

Reply via email to