2

The artifactory archive entry download API systematically fails for a tar.gz archive

The whole archive can be downloaded https://jcr.mydomain/artifactory/osb-cmdb-builds/manual_report.tgz but individual files at https://jcr.mydomain/artifactory/osb-cmdb-builds/manual_report.tgz!/osb-cmdb/build/reports/tests/test/index.html fail with message Unable to find zip resource: 'osb-cmdb/build/reports/tests/test/index.html' using full URI '/artifactory/osb-cmdb-builds/manual_report.tgz!/osb-cmdb/build/reports/tests/test/index.html'

The artifactory repository browser however properly displays content of the archive.

This was reproduced using the docker image jfrog/artifactory-jcr version:7.3.2 and tar

$ tar --version
tar (GNU tar) 1.29
$ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.4 LTS"

Am I missing something ? Is this an artifactory bug fixed in a later release ?

Here are steps to reproduce the issue:

$ tar cvfz manual_report2.tgz ./osb-cmdb/build/reports/tests/test/index.html
$ tar tvfz manual_report2.tgz
-rw-r--r-- guillaume/guillaume 4193 2020-04-01 22:25 ./osb-cmdb/build/reports/tests/test/index.html

See screenshots browsing screenshot entry download screenshot

As well as the sample tgz on google drive as suggested in https://meta.stackexchange.com/questions/47689/how-can-i-attach-a-file-to-a-post

Workaround: use the zip or tar format instead of tar.gz format.

Guillaume Berche
  • 3,049
  • 2
  • 17
  • 18
  • 1
    I tried reproducing, but it works well for me. Can you share the .tgz file you created or instructions on how to create it? – Eldad Assis Apr 02 '20 at 13:41
  • Thanks @EldadAssis for looking into this. I've updated the question with a sample and associated step to create it. Hope this helps reproduce. I suspect the leading ./ I tried adding the leading . in the url without luck. – Guillaume Berche Apr 02 '20 at 14:34

2 Answers2

3

The issue is related to the "." you have in the file's path. You can see the dot as part of the path in the tree browser screenshot. The reason why Artifactory is not finding the file when you try to download is that the path is missing the dot.
The tricky thing about the dot is that it is considered a special symbol which translate into the current directory. If you will try to include it in the URL you are using for downloading the file, the browser will remove it.
However, by using URL encoding I was able to download the file using cURL:

curl -vv "http://localhost:8081/artifactory/generic-local/manual_report2.tgz%21/%2E/osb-cmdb/build/reports/tests/test/index.html"

The following use of URL encoding works with Firefox:

http://localhost:8081/artifactory/generic-local/manual_report2.tgz!%2F./osb-cmdb/build/reports/tests/test/index.html
Dror Bereznitsky
  • 20,048
  • 3
  • 48
  • 57
  • Thanks a lot Dror ! The hint to url encode the path to to archived resource might help other users if added to the documentation https://www.jfrog.com/confluence/display/JFROG/Artifactory+REST+API#ArtifactoryRESTAPI-ArchiveEntryDownload – Guillaume Berche Apr 03 '20 at 07:11
  • While I manage to get the content with curl, pasting the same encoded URL in the browser fails. I suspect the browser (firefox) to perform url normalisation and removes the "." before sending the request to the artifactory server, resulting in 404 – Guillaume Berche Apr 03 '20 at 09:26
  • @GuillaumeBerche I updated the answer with a solution for Firefox – Dror Bereznitsky Apr 05 '20 at 11:26
1

(Refinement of @dror-bereznitsky 's answer )

Avoid the leading ./ in the tar.gz archive.

If the archive paths are dynamically computed (e.g. the result of a find . -name "pattern") then invoke tar command with --transform='s|^\./||S' argument as suggested in https://unix.stackexchange.com/a/250186/381792

$ find . -name "index.html"
./osb-cmdb/build/reports/tests/test/index.html
$ tar cvfz manual_report2.tgz --transform='s|^\./||S' `find . -name "index.html"`
$ tar tvfz manual_report2.tgz
-rw-r--r-- guillaume/guillaume 4193 2020-04-01 22:25 osb-cmdb/build/reports/tests/test/index.html
Guillaume Berche
  • 3,049
  • 2
  • 17
  • 18