Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-19947

Missing base directory in ZIP from .../artifact/dir/subdir/*zip*/subdir.zip

      1.509.x would create a subdir.zip with a root entry subdir/. Development builds omit this top directory.

          [JENKINS-19947] Missing base directory in ZIP from .../artifact/dir/subdir/*zip*/subdir.zip

          Possibly by mistake (the code in question seems to have never previously been subject to automated test), but also possibly to ensure that someone running unzip or the equivalent will always get a single folder as a result—if you forget to unzip to a new destination directory, it can be quite annoying to have your current directory strewn with several dozen new files and subdirectories

          Actually, unzip behaviour differs depending on whether you are Linux or Windows.
          On Linux, the behaviour is as you describe - the unzip writes into the current directory.
          On Windows, unzip creates a new directory with the same name as the .zip file (minus the .zip extension) and then writes into there (that's with the GUI - not sure what the command line does).

          In fact, when we zip up our product, we add an extra directory level in the Linux .zip, but not in the Windows .zip, for exactly that reason.

          Matthew

          Matthew Webber added a comment - Possibly by mistake (the code in question seems to have never previously been subject to automated test), but also possibly to ensure that someone running unzip or the equivalent will always get a single folder as a result—if you forget to unzip to a new destination directory, it can be quite annoying to have your current directory strewn with several dozen new files and subdirectories Actually, unzip behaviour differs depending on whether you are Linux or Windows. On Linux, the behaviour is as you describe - the unzip writes into the current directory. On Windows, unzip creates a new directory with the same name as the .zip file (minus the .zip extension) and then writes into there (that's with the GUI - not sure what the command line does). In fact, when we zip up our product, we add an extra directory level in the Linux .zip, but not in the Windows .zip, for exactly that reason. Matthew

          Daniel Beck added a comment - - edited

          For completeness: OS X (Archive Utility and The Unarchiver) creates a directory named like the zip file when there's more than one top level item in the archive. Otherwise, extracts into the current directory.

          Couldn't we retain the existing behavior for the URL, assuming scripts get their input from /*zip*/ directly, add /*fileszip*/ and only link to the latter on the UI? Or distinguish on the UI between 'files as zip' (without top-level dir) and 'current directory as zip' (old behavior)?

          Another option might be to make this behavior configurable as a UserProperty.

          Daniel Beck added a comment - - edited For completeness: OS X (Archive Utility and The Unarchiver) creates a directory named like the zip file when there's more than one top level item in the archive. Otherwise, extracts into the current directory. Couldn't we retain the existing behavior for the URL, assuming scripts get their input from /*zip*/ directly, add /*fileszip*/ and only link to the latter on the UI? Or distinguish on the UI between 'files as zip' (without top-level dir) and 'current directory as zip' (old behavior)? Another option might be to make this behavior configurable as a UserProperty.

          Jesse Glick added a comment -

          I cannot quite follow the logic in DirectoryBrowserSupport, but it may be possible to append a glob ** to the URL somewhere (as the rest variable), in which case GlobScanner switches to the behavior of not including the parent dir. Anyway such possibilities would be better discussed in a separate RFE; this bug was just about an unintended change of behavior with the new implementation, now reverted.

          Jesse Glick added a comment - I cannot quite follow the logic in DirectoryBrowserSupport , but it may be possible to append a glob ** to the URL somewhere (as the rest variable), in which case GlobScanner switches to the behavior of not including the parent dir. Anyway such possibilities would be better discussed in a separate RFE; this bug was just about an unintended change of behavior with the new implementation, now reverted.

          Daniel Beck added a comment - - edited

          Jesse: Thanks for the hint!

          For reference, /path/to/dir/**/*zip*/foo.zip downloads a file named foo.zip with the contents of /path/to/dir (i.e. no top-level directory named dir in the zip file). /path/to/dir/*/*zip*/foo.zip downloads all the files in the directory dir, without sub-directories.

          To conveniently download these, enter the pattern ** or * into the box in the path bar, see a preview of what you're going to get, and only then click the download link.

          Daniel Beck added a comment - - edited Jesse: Thanks for the hint! For reference, /path/to/dir/**/*zip*/foo.zip downloads a file named foo.zip with the contents of /path/to/dir (i.e. no top-level directory named dir in the zip file). /path/to/dir/*/*zip*/foo.zip downloads all the files in the directory dir , without sub-directories. To conveniently download these, enter the pattern ** or * into the box in the path bar, see a preview of what you're going to get, and only then click the download link.

          Jesse Glick added a comment -

          Thought it was something like that. So then the issue boils down to providing a more discoverable UI for this feature, or picking a better default behavior, etc.

          Jesse Glick added a comment - Thought it was something like that. So then the issue boils down to providing a more discoverable UI for this feature, or picking a better default behavior, etc.

          Victor Baca added a comment -

          This issue may have caused JENKINS-19752 to become an issue again. I am unable to validate that this issue is resolved due to the now corrupt ZIP file.

          Victor Baca added a comment - This issue may have caused JENKINS-19752 to become an issue again. I am unable to validate that this issue is resolved due to the now corrupt ZIP file.

          Code changed in jenkins
          User: Jesse Glick
          Path:
          core/src/main/java/hudson/FilePath.java
          core/src/main/java/hudson/model/DirectoryBrowserSupport.java
          core/src/main/java/hudson/util/DirScanner.java
          test/src/test/java/hudson/model/DirectoryBrowserSupportTest.java
          http://jenkins-ci.org/commit/jenkins/3695e614ed51c344bcc7deafaee44b11f7d1151d
          Log:
          [FIXED JENKINS-19947] Restore historical undocumented behavior of a top-level entry in a ZIP.
          Noting that various DirScanner implementations handle this inconsistently.

          (cherry picked from commit 793b6826e567e20a256a6d4166031e75a185ef7a)

          Conflicts:
          changelog.html

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: core/src/main/java/hudson/FilePath.java core/src/main/java/hudson/model/DirectoryBrowserSupport.java core/src/main/java/hudson/util/DirScanner.java test/src/test/java/hudson/model/DirectoryBrowserSupportTest.java http://jenkins-ci.org/commit/jenkins/3695e614ed51c344bcc7deafaee44b11f7d1151d Log: [FIXED JENKINS-19947] Restore historical undocumented behavior of a top-level entry in a ZIP. Noting that various DirScanner implementations handle this inconsistently. (cherry picked from commit 793b6826e567e20a256a6d4166031e75a185ef7a) Conflicts: changelog.html

          Daniel Beck added a comment -

          Next LTS will be based on 1.554, which contains the original fix, so no backporting required.

          Daniel Beck added a comment - Next LTS will be based on 1.554, which contains the original fix, so no backporting required.

          James Howe added a comment -

          I don't suppose there's any option if I want the directory to be omitted?

          James Howe added a comment - I don't suppose there's any option if I want the directory to be omitted?

          Jesse Glick added a comment -

          jameshowe use ** as an include pattern rather than omitting this parameter or leaving it blank.

          Jesse Glick added a comment - jameshowe use ** as an include pattern rather than omitting this parameter or leaving it blank.

            jglick Jesse Glick
            jglick Jesse Glick
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: