Uploaded image for project: 'Maven Wagon'
  1. Maven Wagon
  2. WAGON-363

wagon-ftp fails to create non-existing directory when path contains "/../"

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.1
    • Fix Version/s: 3.0.0
    • Component/s: wagon-ftp
    • Labels:
      None
    • Environment:
      Maven 3.0.3
      Java 6u29
      Windows 7x64

      Description

      Creating non-existent parent folders as described in WAGON-265 does not work for the following scenario (real ftp-server replaced with "someurl.com"):

      I want to upload the site for a module named "exec-listeners-extension".
      This module inherits from mms-modules-parent (direct parent) which inherits from mms-parent ("transitive" parent).

      All modules/parents have site-urls, whereas the url of exec-listeners-extension is defined as:

      <url>${distributionManagement.site.urlBase}/maven/${project.artifactId}</url>

      $

      {distributionManagement.site.urlBase}

      is defined in mms-parent ("transitive" parent of exec-listeners-extension):

      <distributionManagement.site.urlBase>ftp://reuse-sites.mms-at-work.de/mms/www/reuse-sites</distributionManagement.site.urlBase>

      So the final site location sould be:
      ftp://someurl.com/mms/www/reuse-sites/maven/exec-listeners-extension

      This folder/path does already exist and is writable:
      ftp://someurl.com/mms/www/reuse-sites
      The folder mms-parent within reuse-sites also does already exist.

      The "maven" folder (and it's subfolder "exec-listeners-extension") do not exist and thus need to be created.

      But this is what happens when calling mvn site-deploy:

      Command sent: SYST
      
      Reply received: 215 UNIX Type: L8 Version: SUNOS
      
      Remote system is UNIX Type: L8 Version: SUNOS
      Command sent: TYPE I
      
      Reply received: 200 Type set to I.
      
      ftp://someurl.com/mms/www/reuse-sites/mms-parent/ - Session: Opened
      [INFO] Pushing c:\Develop\_dev\mms-modules\maven\exec-listeners-extension\trunk\target\site
      [INFO]    >>> to ftp://someurl.com/mms/www/reuse-sites/mms-parent/../maven/exec-listeners-extension
      Command sent: CWD /mms/www/reuse-sites/mms-parent/
      
      Reply received: 250 CWD command successful.
      
      Recursively uploading directory c:\Develop\_dev\mms-modules\maven\exec-listeners-extension\trunk\target\site as ../maven/exec-listeners-extension
      processing = c:\Develop\_dev\mms-modules\maven\exec-listeners-extension\trunk\target\site as ../maven/exec-listeners-extension
      Command sent: CWD ../maven/exec-listeners-extension
      
      Reply received: 550 ../maven/exec-listeners-extension: No such file or directory.
      
      Command sent: PWD
      
      Reply received: 257 "/mms/www/reuse-sites/mms-parent" is current directory.
      
      Command sent: CWD ..
      
      Reply received: 250 CWD command successful.
      
      Command sent: CWD ..
      
      Reply received: 250 CWD command successful.
      
      Command sent: PWD
      
      Reply received: 257 "/mms/www" is current directory.
      
      Command sent: CWD maven
      
      Reply received: 550 maven: No such file or directory.
      
      Command sent: MKD maven
      
      Reply received: 550 maven: Permission denied.
      
      Command sent: CWD /mms/www
      
      Reply received: 250 CWD command successful.
      
      Command sent: CWD /mms/www/reuse-sites/mms-parent
      
      Reply received: 250 CWD command successful.
      
      ftp://someurl.com/mms/www/reuse-sites/mms-parent/ - Session: Disconnecting
      ftp://someurl.com/mms/www/reuse-sites/mms-parent/ - Session: Disconnected
      [INFO] ------------------------------------------------------------------------
      [INFO] BUILD FAILURE
      [INFO] ------------------------------------------------------------------------
      [INFO] Total time: 47.461s
      [INFO] Finished at: Fri Dec 09 20:56:09 CET 2011
      [INFO] Final Memory: 33M/961M
      [INFO] ------------------------------------------------------------------------
      [ERROR] Failed to execute goal org.apache.maven.plugins:maven-site-plugin:3.0:deploy (default-deploy) on project exec-listeners-extension: Error uploading site: Unable to create directory ../maven/exec-listeners-extension when processing c:\Develop\_dev\mms-modules\maven\exec-listeners-extension\trunk\target\site -> [Help 1]
      

      Wagon-ftp executes "CWD .." twice which leads to a "Permission denied" later on when trying to create the "maven" folder in "www" (not writable!) instead of "reuse-sites".
      I guess this is because WAGON-265 added an automatic "CWD .." and the path being uses by wagon-ftp already contains "/../":

      [INFO]    >>> to ftp://someurl.com/mms/www/reuse-sites/mms-parent/../maven/exec-listeners-extension

      I don't know why the path already contains a "/../". I guess this is because of the parent relationship?!

        Issue Links

          Activity

          Hide
          michael-o Michael Osipov added a comment -
          Show
          michael-o Michael Osipov added a comment - Fixed with 1247688c22984fe40c6e51ce7c05315c33b10769 .
          Hide
          hudson Hudson added a comment -

          FAILURE: Integrated in Jenkins build maven-wagon #1343 (See https://builds.apache.org/job/maven-wagon/1343/)
          WAGON-363 wagon-ftp fails to create non-existing directory when path (michaelo: http://git-wip-us.apache.org/repos/asf/?p=maven-wagon.git&a=commit&h=1247688c22984fe40c6e51ce7c05315c33b10769)

          • (edit) wagon-providers/wagon-ftp/src/main/java/org/apache/maven/wagon/providers/ftp/FtpWagon.java
          Show
          hudson Hudson added a comment - FAILURE: Integrated in Jenkins build maven-wagon #1343 (See https://builds.apache.org/job/maven-wagon/1343/ ) WAGON-363 wagon-ftp fails to create non-existing directory when path (michaelo: http://git-wip-us.apache.org/repos/asf/?p=maven-wagon.git&a=commit&h=1247688c22984fe40c6e51ce7c05315c33b10769 ) (edit) wagon-providers/wagon-ftp/src/main/java/org/apache/maven/wagon/providers/ftp/FtpWagon.java
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user asfgit closed the pull request at:

          https://github.com/apache/maven-wagon/pull/33

          Show
          githubbot ASF GitHub Bot added a comment - Github user asfgit closed the pull request at: https://github.com/apache/maven-wagon/pull/33
          Hide
          lbreuss Leo Breuss added a comment -

          I've successfully applied and used your patch. I created a pull request: https://github.com/apache/maven-wagon/pull/33

          Show
          lbreuss Leo Breuss added a comment - I've successfully applied and used your patch. I created a pull request: https://github.com/apache/maven-wagon/pull/33
          Hide
          githubbot ASF GitHub Bot added a comment -

          GitHub user lbreuss opened a pull request:

          https://github.com/apache/maven-wagon/pull/33

          WAGON-363 wagon-ftp omit duplicate CWD

          I incorporated the suggested patch and built it inhouse at our company, as version 2.12-WAGON-363. It resolves the problem. (The logic in the code could be restructured a bit to be more readable, but it does the job)

          You can merge this pull request into a Git repository by running:

          $ git pull https://github.com/lbreuss/maven-wagon WAGON-363

          Alternatively you can review and apply these changes as the patch at:

          https://github.com/apache/maven-wagon/pull/33.patch

          To close this pull request, make a commit to your master/trunk branch
          with (at least) the following in the commit message:

          This closes #33


          commit 0b42bb261e1444d1dbd7ebcd6e9604415e1293ed
          Author: Leo Breuss <lbreuss@e3ag.ch>
          Date: 2017-03-21T00:50:43Z

          WAGON-363 wagon-ftp omit duplicate CWD


          Show
          githubbot ASF GitHub Bot added a comment - GitHub user lbreuss opened a pull request: https://github.com/apache/maven-wagon/pull/33 WAGON-363 wagon-ftp omit duplicate CWD I incorporated the suggested patch and built it inhouse at our company, as version 2.12- WAGON-363 . It resolves the problem. (The logic in the code could be restructured a bit to be more readable, but it does the job) You can merge this pull request into a Git repository by running: $ git pull https://github.com/lbreuss/maven-wagon WAGON-363 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/maven-wagon/pull/33.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #33 commit 0b42bb261e1444d1dbd7ebcd6e9604415e1293ed Author: Leo Breuss <lbreuss@e3ag.ch> Date: 2017-03-21T00:50:43Z WAGON-363 wagon-ftp omit duplicate CWD
          Hide
          stefan.braune Stefan Braune added a comment - - edited

          This problem still persists with wagon-ftp:2.4 (and below). I fixed that issue by myself in class org.apache.maven.wagon.providers.ftp.FtpWagon. The issue was, that while making directories recursively, the code tests whether a directory already exists by entering it and seeing whether that worked or not. After that (and maybe after creating the directory) it will enter it again. If the directory already existed (as it is the case for ".."), it enters it a second time. That's the whole bug.

          The original version reads like this:

          FtpWagon.java (original)
                      // we only create the nextDir if it doesn't yet exist
                      if (!ftp.changeWorkingDirectory(nextDir)) {
                          ok &= ftp.makeDirectory(nextDir);
                      }
          
                      if (ok) {
                          // set the permissions for the freshly created directory
                          setPermissions(permissions);
          
                          ftp.changeWorkingDirectory(nextDir);
          
                          // now create the deeper directories
                          final String remainingDirs = fileName.substring(slashPos + 1);
                          ok &= makeFtpDirectoryRecursive(remainingDirs, permissions);
                      }
          

          The fixed version looks like this (notice the changedDir boolean variable, which fixes the whole thing):

          FtpWagon.java (fixed)
                      boolean changedDir = false;
                      // we only create the nextDir if it doesn't yet exist
                      if (!ftp.changeWorkingDirectory(nextDir)) {
                          ok &= ftp.makeDirectory(nextDir);
                      } else {
                          changedDir = true;
                      }
          
                      if (ok) {
                          // set the permissions for the freshly created directory
                          setPermissions(permissions);
          
                          if (!changedDir) {
                              ftp.changeWorkingDirectory(nextDir);
                          }
          
                          // now create the deeper directories
                          final String remainingDirs = fileName.substring(slashPos + 1);
                          ok &= makeFtpDirectoryRecursive(remainingDirs, permissions);
                      }
          

          I hope, that this patch will be integrated soon.

          Show
          stefan.braune Stefan Braune added a comment - - edited This problem still persists with wagon-ftp:2.4 (and below). I fixed that issue by myself in class org.apache.maven.wagon.providers.ftp.FtpWagon. The issue was, that while making directories recursively, the code tests whether a directory already exists by entering it and seeing whether that worked or not. After that (and maybe after creating the directory) it will enter it again. If the directory already existed (as it is the case for ".."), it enters it a second time. That's the whole bug. The original version reads like this: FtpWagon.java (original) // we only create the nextDir if it doesn't yet exist if (!ftp.changeWorkingDirectory(nextDir)) { ok &= ftp.makeDirectory(nextDir); } if (ok) { // set the permissions for the freshly created directory setPermissions(permissions); ftp.changeWorkingDirectory(nextDir); // now create the deeper directories final String remainingDirs = fileName.substring(slashPos + 1); ok &= makeFtpDirectoryRecursive(remainingDirs, permissions); } The fixed version looks like this (notice the changedDir boolean variable, which fixes the whole thing): FtpWagon.java (fixed) boolean changedDir = false ; // we only create the nextDir if it doesn't yet exist if (!ftp.changeWorkingDirectory(nextDir)) { ok &= ftp.makeDirectory(nextDir); } else { changedDir = true ; } if (ok) { // set the permissions for the freshly created directory setPermissions(permissions); if (!changedDir) { ftp.changeWorkingDirectory(nextDir); } // now create the deeper directories final String remainingDirs = fileName.substring(slashPos + 1); ok &= makeFtpDirectoryRecursive(remainingDirs, permissions); } I hope, that this patch will be integrated soon.

            People

            • Assignee:
              michael-o Michael Osipov
              Reporter:
              famod Falko Modler
            • Votes:
              3 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development