-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow for archive downloads without extension #11513
Comments
If Content-Disposition , this might be interesting: https://github.com/cardinalby/phpContentDisposition . |
Yeah I am not sure.. That seems pretty messy to me to do a request just to get the headers, and then do another request with the download after, also you may not have the proper auth setup at that point etc. Just overall not a workable generic solution. Just out of curiosity though, what's the problem you were seeing without this? As far as I know the downloader/archive extraction used is defined by the dist type of the package and the filename/extension has no actual impact, only cosmetic. |
Given a {
"packages": {
"acme\/package": {
"0.0.0-alpha230608": {
"name": "acme\/package",
"version": "0.0.0-alpha230608",
"dist": {
"url": "https:\/\/acme-gitlab.example.org\/public-group\/composer-packages\/-\/package_files\/335\/download",
"type": "tar"
}
},
"0.0.0-alpha230612": {
"name": "acme\/package",
"version": "0.0.0-alpha230612",
"dist": {
"url": "https:\/\/acme-gitlab.example.org\/public-group\/composer-packages\/-\/package_files\/340\/download",
"type": "tar"
}
},
"0.0.0-alpha230613": {
"name": "acme\/package",
"version": "0.0.0-alpha230613",
"dist": {
"url": "https:\/\/acme-gitlab.example.org\/public-group\/composer-packages\/-\/package_files\/337\/download",
"type": "tar"
}
}
}
}
} And a global composer config that uses that repository : {
"repositories": [
{
"type": "composer",
"url": "https://acme-registries.example.org/composer/"
}
]
} Then composer install/update could not unpack the downloaded file.
|
Ok I guess this is a problem of the PharData class needing an extension to identify the file format. Can you try manually opening one of those files with PharData to see if passing Phar::TAR explicitly to $format or some other value would help fix this? See https://www.php.net/manual/en/phardata.construct.php |
php -r '$a = new \PharData("/app/vendor/composer/tmp-dac7ef442f58594e6ad1da088dff7cdb",FilesystemIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS,null,Phar::TAR);'
Fatal error: Uncaught UnexpectedValueException: Cannot create phar '/app/vendor/composer/tmp-dac7ef442f58594e6ad1da088dff7cdb', file extension (or combination) not recognised or the directory does not exist in Command line code:1 |
The downloaded file seems to be downloaded into the cache with a If I use that file instead of the one without extension in ( |
maybe the code could reuse the same logic than for the cache to add the extension |
@stof sorry but what code do you mean? |
I saw this message passing by with composer i -vvv
Seems to be from composer/src/Composer/Cache.php Line 198 in c7bbd60
|
Yeah found the code in question
|
But yes, probably could make sure that if there is no file extension in url we at least append the dist type to the file name.. That'd be an easy fix and might help. |
…ut extension, fixes composer#11513
Ok please try with |
Just remembered the archive is also gzip`ed, but adding that to the PharData::__construct does not work either. It seems that PharData does not look at the file contents at all. Putting an empty file into PharData seems to throw another type off message, it seems: touch f.tar
Fatal error: Uncaught UnexpectedValueException: internal corruption of phar "/app/f.tar" (truncated entry) in Command line code:1 re: if solved: yes, it does solve it for me +1 😃 |
Thanks! |
Ok cool, yes PharData isn't the smartest cookie it seems, but that's all we got to handle tar (and tbh that's one of the reasons we prefer the zip format even tho github does tgz as well..). |
There seems to be a php-native untar. But I can imagine this is not high on the list, as most systems able to produce |
Yeah also this doesn't support tar compression without the zip extension though so it's only so useful.. |
FileDownloader.php its getFileName seems to extract an extension based on the given url.
Recently I came across an archived package publication to a extensionless file name, e.g. ".../download".
Upon inspecting the curl-headers I saw the response included a Content-Disposition header, which I used to detect the extension, which seems to affect the chosen unarchiving procedure.
Later I thought about that Content-Type might be more widely used/available.
Anyway, perhaps a feature to consider adding into composer.
I temporarily resolved my issue by this replacing getFileName its content with this pile of characters.
With php hilighting (as that seems to get lost in the ```diff):
The ```diff:
The text was updated successfully, but these errors were encountered: