Skip to content

Commit

Permalink
fix: cache file names longer than 260
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
StarsbySea authored May 5, 2021
1 parent 3d67b7d commit 43ea17a
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,19 @@ function versiondir($app, $version, $global) { "$(appdir $app $global)\$version"
function persistdir($app, $global) { "$(basedir $global)\persist\$app" }
function usermanifestsdir { "$(basedir)\workspace" }
function usermanifest($app) { "$(usermanifestsdir)\$app.json" }
function cache_path($app, $version, $url) { "$cachedir\$app#$version#$($url -replace '[^\w\.\-]+', '_')" }
function cache_path($app, $version, $url) {
$filename = "$app#$version#$url"
if ($filename.Length -ge 260) {
$url = $url -replace '\?.*', ''
$filename = "$app#$version#$url"
if ($filename.Length -ge 260) {
$filename = "$app#$version#$(Split-Path $url -leaf)"
}
}
$filename = $filename -replace '[^\w\.\-\#]+', '_'
$path = Join-Path $SCOOP_CACHE_DIRECTORY $filename
return $path
}

# apps
function sanitary_path($path) { return [regex]::replace($path, "[/\\?:*<>|]", "") }
Expand Down

0 comments on commit 43ea17a

Please sign in to comment.