You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wagon-commits@maven.apache.org by tr...@apache.org on 2005/09/21 15:49:39 UTC

svn commit: r290696 - in /maven/wagon/trunk/wagon-providers/wagon-ssh: src/main/java/org/apache/maven/wagon/providers/ssh/ScpWagon.java src/main/java/org/apache/maven/wagon/providers/ssh/SftpWagon.java xdocs/changes.xml xdocs/index.xml

Author: trygvis
Date: Wed Sep 21 06:49:32 2005
New Revision: 290696

URL: http://svn.apache.org/viewcvs?rev=290696&view=rev
Log:
Fixing WAGONSSH-11: "sftp: implement method getIfNewer()"
Patch 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
    maven/wagon/trunk/wagon-providers/wagon-ssh/xdocs/changes.xml
    maven/wagon/trunk/wagon-providers/wagon-ssh/xdocs/index.xml

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=290696&r1=290695&r2=290696&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 Wed Sep 21 06:49:32 2005
@@ -123,7 +123,7 @@
                 else
                 {
                     String msg = "Private key was not found. You must define a private key or a password for repo: " +
-                        getRepository().getName();
+                                 getRepository().getName();
 
                     throw new AuthenticationException( msg );
                 }
@@ -251,10 +251,10 @@
                 executeCommand( umaskCmd );
             }
         }
-        
-        String mkdirCmd = umaskCmd + "mkdir -p -m " 
-                          + getRepository().getPermissions().getDirectoryMode() 
-                          + " "+ basedir + "/" + dir + "\n";
+
+        String mkdirCmd = umaskCmd + "mkdir -p -m "
+                          + getRepository().getPermissions().getDirectoryMode()
+                          + " " + basedir + "/" + dir + "\n";
 
         executeCommand( mkdirCmd );
 
@@ -318,7 +318,7 @@
             byte[] buf = new byte[1024];
 
             // send '\0'
-            buf[0] = 0;
+            buf[ 0 ] = 0;
 
             out.write( buf, 0, 1 );
 
@@ -332,14 +332,14 @@
         catch ( IOException e )
         {
             String msg = "Error occured while deploying '" + resourceName + "' to remote repository: " +
-                getRepository().getUrl();
+                         getRepository().getUrl();
 
             throw new TransferFailedException( msg, e );
         }
         catch ( JSchException e )
         {
             String msg = "Error occured while deploying '" + resourceName + "' to remote repository: " +
-                getRepository().getUrl();
+                         getRepository().getUrl();
 
             throw new TransferFailedException( msg, e );
         }
@@ -408,7 +408,7 @@
             byte[] buf = new byte[1024];
 
             // send '\0'
-            buf[0] = 0;
+            buf[ 0 ] = 0;
 
             out.write( buf, 0, 1 );
 
@@ -425,37 +425,46 @@
                 }
 
                 // read '0644 '
-                in.read( buf, 0, 5 );
+                if ( in.read( buf, 0, 5 ) != 5 )
+                {
+                    throw new TransferFailedException( "Unexpected end of data." );
+                }
 
                 int filesize = 0;
 
                 // get file size
                 while ( true )
                 {
-                    in.read( buf, 0, 1 );
+                    if ( in.read( buf, 0, 1 ) != 1 )
+                    {
+                        throw new TransferFailedException( "Unexpected end of data." );
+                    }
 
-                    if ( buf[0] == ' ' )
+                    if ( buf[ 0 ] == ' ' )
                     {
                         break;
                     }
 
-                    filesize = filesize * 10 + ( buf[0] - '0' );
+                    filesize = filesize * 10 + ( buf[ 0 ] - '0' );
                 }
 
                 resource.setContentLength( filesize );
 
                 for ( int i = 0; ; i++ )
                 {
-                    in.read( buf, i, 1 );
+                    if ( in.read( buf, i, 1 ) != 1 )
+                    {
+                        throw new TransferFailedException( "Unexpected end of data." );
+                    }
 
-                    if ( buf[i] == (byte) 0x0a )
+                    if ( buf[ i ] == (byte) 0x0a )
                     {
                         break;
                     }
                 }
 
                 // send '\0'
-                buf[0] = 0;
+                buf[ 0 ] = 0;
 
                 out.write( buf, 0, 1 );
 
@@ -472,7 +481,10 @@
                     {
                         int len = Math.min( buf.length, filesize );
 
-                        in.read( buf, 0, len );
+                        if ( in.read( buf, 0, len ) != len )
+                        {
+                            throw new TransferFailedException( "Unexpected end of data." );
+                        }
 
                         outputStream.write( buf, 0, len );
 
@@ -520,7 +532,7 @@
                 }
 
                 // send '\0'
-                buf[0] = 0;
+                buf[ 0 ] = 0;
 
                 out.write( buf, 0, 1 );
 
@@ -571,6 +583,7 @@
     }
 
     public boolean getIfNewer( String resourceName, File destination, long timestamp )
+        throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
     {
         throw new UnsupportedOperationException( "getIfNewer is scp wagon must be still implemented" );
     }
@@ -579,6 +592,7 @@
 // JSch user info
 // ----------------------------------------------------------------------
 // TODO: are the prompt values really right? Is there an alternative to UserInfo?
+
     public static class WagonUserInfo
         implements UserInfo
     {

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=290696&r1=290695&r2=290696&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 Wed Sep 21 06:49:32 2005
@@ -86,7 +86,7 @@
 
             RepositoryPermissions permissions = getRepository().getPermissions();
 
-            mkdirs( channel, resourceName, getDirectoryMode(permissions));
+            mkdirs( channel, resourceName, getDirectoryMode( permissions ) );
 
             firePutStarted( resource, source );
 
@@ -161,8 +161,8 @@
     private int getDirectoryMode( RepositoryPermissions permissions )
     {
         int ret = -1;
-        
-        if ( permissions != null ) 
+
+        if ( permissions != null )
         {
             try
             {
@@ -175,7 +175,7 @@
                 ret = -1;
             }
         }
-        
+
         return ret;
     }
 
@@ -187,21 +187,22 @@
         {
             try
             {
-                SftpATTRS attrs = channel.stat( dirs[i] );
+                SftpATTRS attrs = channel.stat( dirs[ i ] );
                 if ( ( attrs.getPermissions() & S_IFDIR ) == 0 )
                 {
-                    throw new TransferFailedException( "Remote path is not a directory:" + PathUtils.dirname( resourceName ) );
+                    throw new TransferFailedException(
+                        "Remote path is not a directory:" + PathUtils.dirname( resourceName ) );
                 }
             }
             catch ( SftpException e )
             {
                 // doesn't exist, make it and try again
-                channel.mkdir( dirs[i] );
+                channel.mkdir( dirs[ i ] );
                 if ( mode != -1 )
                 {
                     try
                     {
-                        channel.chmod( mode, dirs[i] );
+                        channel.chmod( mode, dirs[ i ] );
                     }
                     catch ( final SftpException e1 )
                     {
@@ -211,13 +212,14 @@
                 }
             }
 
-            channel.cd( dirs[i] );
+            channel.cd( dirs[ i ] );
         }
     }
 
-    public void get( String resourceName, File destination )
+    public boolean getIfNewer( String resourceName, File destination, long timestamp )
         throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
     {
+        boolean bDownloaded = true;
         createParentDirectories( destination );
 
         ChannelSftp channel;
@@ -226,6 +228,12 @@
         String dir = PathUtils.dirname( resourceName );
         dir = StringUtils.replace( dir, "\\", "/" );
 
+        // we already setuped the root directory. Ignore beginning /
+        if ( dir.length() > 0 && dir.charAt( 0 ) == '/' )
+        {
+            dir = dir.substring( 1 );
+        }
+
         Resource resource = new Resource( resourceName );
 
         fireGetInitiated( resource, destination );
@@ -250,18 +258,28 @@
 
             channel.cd( dir );
 
-            fireGetStarted( resource, destination );
+            if ( timestamp <= 0 || channel.stat( filename ).getMTime() * 1000L > timestamp )
+            {
+                fireGetStarted( resource, destination );
 
-            channel.get( filename, destination.getAbsolutePath() );
+                channel.get( filename, destination.getAbsolutePath() );
 
-            postProcessListeners( resource, destination, TransferEvent.REQUEST_GET );
+                postProcessListeners( resource, destination, TransferEvent.REQUEST_GET );
 
-            fireGetCompleted( resource, destination );
+                fireGetCompleted( resource, destination );
 
-            String[] dirs = PathUtils.dirnames( dir );
-            for ( int i = 0; i < dirs.length; i++ )
+                String[] dirs = PathUtils.dirnames( dir );
+
+                for ( int i = 0; i < dirs.length; i++ )
+                {
+                    channel.cd( ".." );
+                }
+
+                bDownloaded = true;
+            }
+            else
             {
-                channel.cd( ".." );
+                bDownloaded = false;
             }
         }
         catch ( SftpException e )
@@ -272,10 +290,14 @@
         {
             handleGetException( resource, e, destination );
         }
+
+        return bDownloaded;
     }
 
-    public boolean getIfNewer( String resourceName, File destination, long timestamp )
+
+    public void get( String resourceName, File destination )
+        throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
     {
-        throw new UnsupportedOperationException( "getIfNewer is scp wagon must be still implemented" );
+        getIfNewer( resourceName, destination, 0 );
     }
 }

Modified: maven/wagon/trunk/wagon-providers/wagon-ssh/xdocs/changes.xml
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-providers/wagon-ssh/xdocs/changes.xml?rev=290696&r1=290695&r2=290696&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/xdocs/changes.xml (original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/xdocs/changes.xml Wed Sep 21 06:49:32 2005
@@ -7,7 +7,7 @@
   <body>
     <release version="1.0-beta-1" date="in CVS">
       <action dev="mmaczka" type="add">
-                Imported to Apache CVS
+        Imported to Apache CVS
       </action>
     </release>
   </body>

Modified: maven/wagon/trunk/wagon-providers/wagon-ssh/xdocs/index.xml
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-providers/wagon-ssh/xdocs/index.xml?rev=290696&r1=290695&r2=290696&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/xdocs/index.xml (original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/xdocs/index.xml Wed Sep 21 06:49:32 2005
@@ -1,39 +1,27 @@
-<?xml version="1.0"?>
-
 <document>
-
   <properties>
     <title>Wagon File provider</title>
     <author email="michal.maczka@dimatics.com">Michal Maczka</author>
   </properties>
-
   <body>
-
     <section name="Wagon SCH provider">
       <p>
-               This project is an implementation of Wagon provider
-               for
-        <b>scp</b> and
-        <b>sftp</b> protocols
-               using
-        <a href="http://www.jcraft.com/jsch/">JSCH</a>  library
+        This project is an implementation of Wagon provider for <b>scp</b> and <b>sftp</b> protocols using
+        <a href="http://www.jcraft.com/jsch/">JSCH</a> library
       </p>
     </section>
     <section name="Features">
       <p>
         <ul>
           <li>
-                      SCP and SFTP protocols are supported.
+            SCP and SFTP protocols are supported.
           </li>
           <li>
-            <b>PUT</b> and
-            <b>GET</b>  requests are
-                      are supported for both protocols.
+            <b>PUT</b> and <b>GET</b> requests are are supported for both protocols.
           </li>
           <li>
-                       SCH Wagon is able to set remote UNIX group
-                       for deployed resource (see: xxx ), but for SFTP protocol
-                       group id should be a positive integer.
+            SCH Wagon is able to set remote UNIX group for deployed resource (see: xxx ), but for SFTP protocol
+            group id should be a positive integer.
           </li>
         </ul>
       </p>



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