maven-wagon-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tryg...@apache.org
Subject svn commit: r278806 - in /maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh: ScpWagon.java SftpWagon.java
Date Mon, 05 Sep 2005 18:32:14 GMT
Author: trygvis
Date: Mon Sep  5 11:32:08 2005
New Revision: 278806

URL: http://svn.apache.org/viewcvs?rev=278806&view=rev
Log:
Fixing WAGONSSH-8: "patch: scp: honour repository directory permission mode"
       WAGONSSH-9: "patch: sftp: honour repository directory permission mode"
o Patches created by Juan F. Codagnone.

Modified:
    maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/ScpWagon.java
    maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/SftpWagon.java

Modified: maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/ScpWagon.java
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/ScpWagon.java?rev=278806&r1=278805&r2=278806&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/ScpWagon.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/ScpWagon.java
Mon Sep  5 11:32:08 2005
@@ -241,7 +241,20 @@
 
         firePutInitiated( resource, source );
 
-        String mkdirCmd = "mkdir -p " + basedir + "/" + dir + "\n";
+        String umaskCmd = "";
+        if ( getRepository().getPermissions() != null )
+        {
+            final String dirPerms = getRepository().getPermissions().getDirectoryMode();
+            if ( dirPerms != null )
+            {
+                umaskCmd = "umask " + PermissionModeUtils.getUserMaskFor( dirPerms ) + "\n";
+                executeCommand( umaskCmd );
+            }
+        }
+        
+        String mkdirCmd = umaskCmd + "mkdir -p -m " 
+                          + getRepository().getPermissions().getDirectoryMode() 
+                          + " "+ basedir + "/" + dir + "\n";
 
         executeCommand( mkdirCmd );
 
@@ -365,7 +378,7 @@
         //I/O streams for remote scp
         OutputStream out = null;
 
-        InputStream in = null;
+        InputStream in;
 
         createParentDirectories( destination );
 
@@ -650,7 +663,7 @@
                     throw new TransferFailedException( message );
                 }
             }
-            if ( b == 2 )
+            else
             {
                 // fatal error
                 throw new TransferFailedException( message );

Modified: maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/SftpWagon.java
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/SftpWagon.java?rev=278806&r1=278805&r2=278806&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/SftpWagon.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/SftpWagon.java
Mon Sep  5 11:32:08 2005
@@ -63,9 +63,10 @@
 
         firePutInitiated( resource, source );
 
-        ChannelSftp channel = null;
+        ChannelSftp channel;
 
         String filename;
+
         if ( resourceName.lastIndexOf( '/' ) > 0 )
         {
             filename = resourceName.substring( resourceName.lastIndexOf( '/' ) + 1 );
@@ -83,7 +84,9 @@
 
             channel.cd( basedir );
 
-            mkdirs( channel, resourceName );
+            RepositoryPermissions permissions = getRepository().getPermissions();
+
+            mkdirs( channel, resourceName, getDirectoryMode(permissions));
 
             firePutStarted( resource, source );
 
@@ -91,8 +94,6 @@
 
             postProcessListeners( resource, source, TransferEvent.REQUEST_PUT );
 
-            RepositoryPermissions permissions = getRepository().getPermissions();
-
             if ( permissions != null && permissions.getGroup() != null )
             {
                 int group;
@@ -133,15 +134,15 @@
         }
         catch ( SftpException e )
         {
-            String msg = "Error occured while deploying '" + resourceName + "' to remote
repository: " +
-                getRepository().getUrl();
+            String msg = "Error occured while deploying '" + resourceName + "' " +
+                         "to remote repository: " + getRepository().getUrl();
 
             throw new TransferFailedException( msg, e );
         }
         catch ( JSchException e )
         {
-            String msg = "Error occured while deploying '" + resourceName + "' to remote
repository: " +
-                getRepository().getUrl();
+            String msg = "Error occured while deploying '" + resourceName + "' " +
+                         "to remote repository: " + getRepository().getUrl();
 
             throw new TransferFailedException( msg, e );
         }
@@ -152,7 +153,27 @@
         }
     }
 
-    private void mkdirs( ChannelSftp channel, String resourceName )
+    /**
+     * @param permissions repository's permissions
+     * @return the directory mode for the repository or <code>-1</code> if it
+     *         wasn't set
+     */
+    private int getDirectoryMode( RepositoryPermissions permissions )
+    {
+        try
+        {
+            return Integer.valueOf( permissions.getDirectoryMode(), 8 ).intValue();
+        }
+        catch ( NumberFormatException e )
+        {
+            // TODO: warning level
+            fireTransferDebug( "the file mode must be a numerical mode for SFTP" );
+
+            return -1;
+        }
+    }
+
+    private void mkdirs( ChannelSftp channel, String resourceName, int mode )
         throws TransferFailedException, SftpException
     {
         String[] dirs = PathUtils.dirnames( resourceName );
@@ -170,6 +191,18 @@
             {
                 // doesn't exist, make it and try again
                 channel.mkdir( dirs[i] );
+                if ( mode != -1 )
+                {
+                    try
+                    {
+                        channel.chmod( mode, dirs[i] );
+                    }
+                    catch ( final SftpException e1 )
+                    {
+                        // for some extrange reason we recive this exception,
+                        // even when chmod success
+                    }
+                }
             }
 
             channel.cd( dirs[i] );



---------------------------------------------------------------------
To unsubscribe, e-mail: wagon-cvs-unsubscribe@maven.apache.org
For additional commands, e-mail: wagon-cvs-help@maven.apache.org


Mime
View raw message