-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
fix: cache file names longer than 260 #4349
fix: cache file names longer than 260 #4349
Conversation
@StarsbySea which manifest currently faces the issue? |
like this: https://github.com/42wim/scoop-bucket/blob/master/bucket/msedge-stable.json |
I'd prefer this code to prevent the reach of windows MAX_PATH limitation with the temporary file extensions (`.download) added while downloading .. function cache_path($app, $version, $url) {
$MAX_PATH=260
$downloadExt='.download'
$cachefile = "$cachedir\$app#$version#$($url -replace '[^\w\.\-]+', '_')"
$cachefile = $cachefile.substring(0, [System.Math]::Min($MAX_PATH, $cachefile.Length) - $downloadExt.Length)
return $cachefile
} I had the problem with downloading googlechrome extensions like: Local test successful.. An other solution will be to create a SHA1 of the computed string as download filename vs. directly save it, as follow (but not tested): function cache_path($app, $version, $url) {
$enc = [system.Text.Encoding]::UTF8
$sha1 = New-Object System.Security.Cryptography.SHA1CryptoServiceProvider
$hash = $sha1.ComputeHash($enc.GetBytes($url))
$cachefile="$app#$version#$($hash)" -replace '\s',''
"$cachedir/$cachefile"
} |
@StarsbySea please retarget this PR to develop branch |
The PR won't work because you are testing the file name, not the file path. I prefer the 2nd solution mentioned by @mbl-35. |
also, should it be only 259 letters because of the NULL termination?
But using SHA1 for the URL is the better option. |
Fix: ScoopInstaller#4327 Normally, this function behaves as before when the cache filename is less than 260 characters long. The modified program is designed to shorten cached filenames while retaining as much complete URL information as possible. If the filename is greater than or equal to 260 characters in length, it will first attempt to remove everything after the question mark from the URL, and if it is still greater than 260 in length, only the filename in the URL will be retained. Tested locally and passed.
43ea17a
to
e1ff651
Compare
Following @mbl-35 and @r15ch13's suggestion, some changes have been made, as follows: The final output filename is composed as follows: "$cachedir": This is the directory where the cached files are stored. So, for example, if the application is "app1", the version is "v1.0", and the SHA1 hash of the URL is "abc123", and the cache directory is at "C:\cache", the output will be: "C:\cache\app1#v1.0#abc123". |
Signed-off-by: StarsbySea <66008060+StarsbySea@users.noreply.github.com>
Signed-off-by: StarsbySea <66008060+StarsbySea@users.noreply.github.com>
@StarsbySea Is there any advantage of using SHA256 instead of SHA1? Since cryptographic security is not a priority here, SHA1 would be better as it is shorter. |
Inherited by #5929 |
Fix: #4327
Normally, this function behaves as before when the cache filename is less than 260 characters long.
The modified program is designed to shorten cached filenames while retaining as much complete URL information as possible.
If the filename is greater than or equal to 260 characters in length, it will first attempt to remove everything after the question mark from the URL, and if it is still greater than 260 in length, only the filename in the URL will be retained.
Tested locally and passed.