You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2018/06/04 18:54:00 UTC

[jira] [Commented] (WAGON-503) Directory gives out of date error in putDirectory() to a non-empty Subversion repo

    [ https://issues.apache.org/jira/browse/WAGON-503?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16500721#comment-16500721 ] 

ASF GitHub Bot commented on WAGON-503:
--------------------------------------

asfgit closed pull request #47: [WAGON-503] fix Directory is out of date error in putDirectory() to a non-empty svn repo
URL: https://github.com/apache/maven-wagon/pull/47
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/wagon-providers/wagon-scm/src/main/java/org/apache/maven/wagon/providers/scm/ScmWagon.java b/wagon-providers/wagon-scm/src/main/java/org/apache/maven/wagon/providers/scm/ScmWagon.java
index d6531eef..ecffc452 100644
--- a/wagon-providers/wagon-scm/src/main/java/org/apache/maven/wagon/providers/scm/ScmWagon.java
+++ b/wagon-providers/wagon-scm/src/main/java/org/apache/maven/wagon/providers/scm/ScmWagon.java
@@ -100,6 +100,8 @@
      */
     private String partCOSubdir = "";
 
+    private boolean haveRecursiveCO;
+
     private File checkoutDirectory;
 
     /**
@@ -246,7 +248,7 @@ private void removeCheckoutDirectory()
 
         try
         {
-            FileUtils.deleteDirectory( checkoutDirectory );
+            deleteCheckoutDirectory();
         }
         catch ( IOException e )
         {
@@ -378,7 +380,20 @@ private void putInternal( File source, String targetName )
 
             boolean isDirectory = source.isDirectory();
             String checkoutTargetName = isDirectory ? targetName : getDirname( targetName );
-            String relPath = ensureDirs( scmProvider, scmRepository, checkoutTargetName, target );
+            boolean recursive = false;
+            if ( isDirectory )
+            {
+                for ( File f : source.listFiles() )
+                {
+                    if ( f.isDirectory() )
+                    {
+                        recursive = true;
+                        break;
+                    }
+                }
+            }
+
+            String relPath = ensureDirs( scmProvider, scmRepository, checkoutTargetName, target, recursive );
 
             File newCheckoutDirectory = new File( checkoutDirectory, relPath );
 
@@ -448,7 +463,7 @@ private void putInternal( File source, String targetName )
      * @throws IOException
      */
     private String ensureDirs( ScmProvider scmProvider, ScmRepository scmRepository, String targetName,
-                             Resource resource )
+                               Resource resource, boolean recursiveArg )
         throws TransferFailedException, IOException
     {
         if ( checkoutDirectory == null )
@@ -463,11 +478,13 @@ private String ensureDirs( ScmProvider scmProvider, ScmRepository scmRepository,
         // Check whether targetName, which is a relative path into the scm, exists.
         // If it doesn't, check the parent, etc.
 
+        boolean recursive = recursiveArg;
+
         for ( ;; )
         {
             try
             {
-                ScmResult res = tryPartialCheckout( target );
+                ScmResult res = tryPartialCheckout( target, recursive );
                 if ( !res.isSuccess() )
                 {
                     throw new ScmException( "command failed: " + res.getCommandOutput().trim() );
@@ -476,6 +493,7 @@ private String ensureDirs( ScmProvider scmProvider, ScmRepository scmRepository,
             }
             catch ( ScmException e )
             {
+                recursive = false;
                 if ( partCOSubdir.length() == 0 )
                 {
                     fireTransferError( resource, e, TransferEvent.REQUEST_GET );
@@ -598,14 +616,15 @@ private int addFiles( ScmProvider scmProvider, ScmRepository scmRepository, File
         return addedFiles;
     }
 
-    private CheckOutScmResult checkOut( ScmProvider scmProvider, ScmRepository scmRepository, ScmFileSet fileSet )
+    private CheckOutScmResult checkOut( ScmProvider scmProvider, ScmRepository scmRepository, ScmFileSet fileSet,
+                                        boolean recursive )
         throws ScmException
     {
         ScmVersion ver = makeScmVersion();
         CommandParameters parameters = mkBinaryFlag();
         // TODO: AbstractScmProvider 6f7dd0c ignores checkOut() parameter "version"
         parameters.setScmVersion( CommandParameter.SCM_VERSION, ver );
-        parameters.setString( CommandParameter.RECURSIVE, Boolean.toString( false ) );
+        parameters.setString( CommandParameter.RECURSIVE, Boolean.toString( recursive ) );
         parameters.setString( CommandParameter.SHALLOW, Boolean.toString( true ) );
 
         return scmProvider.checkOut( scmRepository, fileSet, ver, parameters );
@@ -632,6 +651,12 @@ private boolean supportsPartialCheckout( ScmProvider scmProvider )
         return ( "svn".equals( scmType ) || "cvs".equals( scmType ) );
     }
 
+    private boolean isAlwaysRecursive( ScmProvider scmProvider )
+    {
+        String scmType = scmProvider.getScmType();
+        return ( "git".equals( scmType ) || "cvs".equals( scmType ) );
+    }
+
     public void putDirectory( File sourceDirectory, String destinationDirectory )
         throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
     {
@@ -691,7 +716,7 @@ public void get( String resourceName, File destination )
         try
         {
             String subdir = getDirname( resourceName );
-            ScmResult res = tryPartialCheckout( subdir );
+            ScmResult res = tryPartialCheckout( subdir, false );
             if ( !res.isSuccess() && ( partCOSubdir.length() == 0 || res instanceof UpdateScmResult ) )
             {
                 // inability to checkout SVN or CVS subdir is not fatal. We just assume it doesn't exist
@@ -737,7 +762,7 @@ public void get( String resourceName, File destination )
         fireGetCompleted( resource, destination );
     }
 
-    private ScmResult tryPartialCheckout( String subdir )
+    private ScmResult tryPartialCheckout( String subdir, boolean recursiveArg )
         throws ScmException, IOException
     {
         String url = getRepository().getUrl();
@@ -755,12 +780,19 @@ private ScmResult tryPartialCheckout( String subdir )
             scmRepository = getScmRepository( url );
         }
 
+        boolean recursive = recursiveArg | isAlwaysRecursive( scmProvider );
+
         if ( !desiredPartCOSubdir.equals( partCOSubdir ) )
         {
-            FileUtils.deleteDirectory( checkoutDirectory );
+            deleteCheckoutDirectory();
             partCOSubdir = desiredPartCOSubdir;
         }
 
+        if ( recursive && !haveRecursiveCO )
+        {
+            deleteCheckoutDirectory();
+        }
+
         ScmResult res;
         if ( checkoutDirExists( scmProvider ) )
         {
@@ -768,11 +800,19 @@ private ScmResult tryPartialCheckout( String subdir )
         }
         else
         {
-            res = checkOut( scmProvider, scmRepository, new ScmFileSet( checkoutDirectory ) );
+            res = checkOut( scmProvider, scmRepository, new ScmFileSet( checkoutDirectory ), recursive );
+            haveRecursiveCO = recursive && res.isSuccess();
         }
         return res;
     }
 
+    private void deleteCheckoutDirectory()
+        throws IOException
+    {
+        haveRecursiveCO = false;
+        FileUtils.deleteDirectory( checkoutDirectory );
+    }
+
     private boolean checkoutDirExists( ScmProvider scmProvider )
     {
         String reservedScmFile = scmProvider.getScmSpecificFilename();
diff --git a/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/AbstractScmWagonTest.java b/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/AbstractScmWagonTest.java
index 30289970..b34ceded 100644
--- a/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/AbstractScmWagonTest.java
+++ b/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/AbstractScmWagonTest.java
@@ -46,6 +46,16 @@
     extends WagonTestCase
 {
 
+    @Override
+    public void testWagonPutDirectory() throws Exception
+    {
+        super.testWagonPutDirectory();
+        // repeat the test on a non-empty repo
+        // ScmWagon should checkout all involved subdirs before calling
+        // FileUtils.copyDirectoryStructure()
+        super.testWagonPutDirectory();
+    }
+
     private ScmWagon wagon;
 
     private String providerClassName;


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Directory gives out of date error in putDirectory() to a non-empty Subversion repo
> ----------------------------------------------------------------------------------
>
>                 Key: WAGON-503
>                 URL: https://issues.apache.org/jira/browse/WAGON-503
>             Project: Maven Wagon
>          Issue Type: Bug
>          Components: wagon-scm
>    Affects Versions: 3.0.0, 3.1.0
>            Reporter: Ilya Basin
>            Assignee: Michael Osipov
>            Priority: Major
>             Fix For: 3.1.0
>
>
> ScmWagon checks out target directory non-recursively, calls FileUtils.copyDirectoryStructure() and then tries to add and checkin these files.
> However, from the perspective of svn ScmWagon is trying to re-add existing folders which is an error.
> Normally, you would explicitly "svn up subdir", but the scm API does not support that. Instead I will erase existing checkout dir and perform a new checkout, recursive this time.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)