ScoopInstaller / Scoop

A command-line installer for Windows.
https://scoop.sh
Other
21.23k stars 1.41k forks source link

[Bug] Fail to download app with long url in manifest #5606

Closed iamhyc closed 1 year ago

iamhyc commented 1 year ago

Bug Report

Current Behavior

With the example manifest here, the current scoop (v0.3.1) will give the error messages pasted below and fail to download the software.

Expected Behavior

The software should be downloaded in the cache folder.

Additional context/output

PS > scoop install deveco-studio
Installing 'deveco-studio' (4.0.0.400) [64bit] from sudofree-bucket bucket

文件名、目录名或卷标语法不正确。 : 'C:\Users\iamhy\scoop\cache\deveco-studio#4.0.0.400#https_contentcenter-vali-drcn.dbankcdn.cn_pvt_2_DeveloperAlliance_package_901_9_9b_v3_2g1w9tlbQPevu9IkTNRhNw_devecostudio-windows-4.0.0.400.zip_HW-CC-KV_V1_HW-CC-Date_20230804T022932Z_HW-CC-Expire_315360000_HW-CC-Sign_23242113800451447FF87450B938F6B3A3B27A7360C10FBF7BCAB10B24473326.download'
URL https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_package_901_9/9b/v3/2g1w9tlbQPevu9IkTNRhNw/devecostudio-windows-4.0.0.400.zip?HW-CC-KV=V1&HW-CC-Date=20230804T022932Z&HW-CC-Expire=315360000&HW-CC-Sign=23242113800451447FF87450B938F6B3A3B27A7360C10FBF7BCAB10B24473326 is not valid

I tried to make powershell output en-US error message but failed. For your convenience, "文件名、目录名或卷标语法不正确" means "The filename directory name or volume label syntax is incorrect".

Possible Solution

I find the error happens because [io.file]::openwrite on "lib/install.ps1#L435" fails to handle the long path name and raises a PathTooLongException. As a workaround, I truncate the cached full path length to 260.

diff --git a/lib/install.ps1 b/lib/install.ps1
index cdbfdf1a..0ab1d49c 100644
--- a/lib/install.ps1
+++ b/lib/install.ps1
@@ -82,6 +82,7 @@ function install_app($app, $architecture, $global, $suggested, $use_cache = $tru

 function Invoke-CachedDownload ($app, $version, $url, $to, $cookies = $null, $use_cache = $true) {
     $cached = fullpath (cache_path $app $version $url)
+    $cached = $cached.subString(0, [System.Math]::min(260, $cached.Length))

     if(!(test-path $cached) -or !$use_cache) {
         ensure $cachedir | Out-Null

System details

Windows version: 10

OS architecture: 64bit

PowerShell version: 7.3.6

Additional software: N/A

Scoop Configuration

{
  "aria2-warning-enabled": false,
  "aria2-enabled": false,
  "last_update": "2023-08-11T18:46:19.5948020+08:00",
  "scoop_repo": "https://github.com/ScoopInstaller/Scoop",
  "scoop_branch": "master"
}
rashil2000 commented 1 year ago

Duplicate of #4327