@@ -24,24 +24,40 @@ string getGitDownloadLink(string packageName, string repo, string branch)
2424 downloadLink = repo~ " /-/archive/" ~ branch~ " /" ~ encodeComponent(packageName)~ " -" ~ branch~ " .zip" ;
2525 else if (repo.canFind(" bitbucket.com" ))
2626 downloadLink = repo~ " /get/" ~ encodeComponent(packageName)~ " -" ~ branch~ " .zip" ;
27- else
27+ else if (repo.canFind( " github.com " ))
2828 {
29- // /Github, Gitea and GitBucket all use the same style
29+ // Github has changed recently to other format.
30+ if (branch.length)
31+ {
32+ if (branch[0 ] == ' ~' )
33+ downloadLink = repo~ " /archive/refs/heads/" ~ branch[1 .. $]~ " .zip" ;
34+ else
35+ downloadLink = repo~ " /archive/refs/tags/" ~ branch~ " .zip" ;
36+ }
37+ else
38+ throw new Exception (" Unexpected Empty Branch." );
39+ }
40+ else
41+ {
42+ // /Gitea and GitBucket all use the same style
3043 downloadLink = repo~ " /archive/" ~ branch~ " .zip" ;
3144 }
3245 return downloadLink;
3346}
3447
3548string getDownloadLink (string packageName, string repo, SemVer requirement, out SemVer actualVer)
3649{
37- if (requirement.isInvalid )
50+ if (repo.length )
3851 {
39- if (! repo)
40- throw new Exception (" Can't have invalid requirement '" ~ requirement.toString~ " ' and have no 'repository' information.
41- \n Example of repository with branch usage: \" redub\" : {\" version\" : \" ~master\" , \" repository\" : \" git+https://github.com/MrcSnm/redub.git\" }" );
52+ if (! requirement.isInvalid)
53+ throw new Exception (" Package '" ~ packageName~ " ' should specify a repository branch, not semver: [" ~ requirement.toString ~
54+ " ]\n\t Example of repository with branch usage: \" redub\" : {\" version\" : \" ~master\" , \" repository\" : \" git+https://github.com/MrcSnm/redub.git\" }" ~
55+ " \n\t Branches should start with '~' otherwise, in github, it will be treated as a tag." );
4256 actualVer = requirement;
4357 return getGitDownloadLink (packageName, repo, requirement.toString);
4458 }
59+ else if (requirement.isInvalid)
60+ throw new Exception (" version for package '" ~ packageName~ " ' is invalid [" ~ requirement.toString~ " ]. verion may only be used as a git branch if a \" repository\" is specified." );
4561 return supplier.getBestPackageDownloadUrl(packageName, requirement, actualVer);
4662}
4763
@@ -81,11 +97,29 @@ ubyte[] fetchPackage(string packageName, string repo, SemVer requirement, out Se
8197string downloadPackageTo (return string path, string packageName, string repo, SemVer requirement, out SemVer out_actualVersion, out string url)
8298{
8399 import redub.libs.package_suppliers.utils;
100+ import redub.logging;
101+ import std.zip ;
84102 ubyte [] zipContent = fetchPackage(packageName, repo, requirement, out_actualVersion, url);
85103 if (! zipContent)
86104 return null ;
87- if (! extractZipToFolder(zipContent, path))
88- throw new Exception (" Error while trying to extract zip to path " ~ path);
105+
106+ if (hasLogLevel(LogLevel.verbose))
107+ vlog(" Extracting package " ,packageName, " from repository " , repo, " with branch " , requirement.toString, " to path " , path, " [" ,url," ]" );
108+
109+ bool extracted = false ;
110+ try
111+ {
112+ extracted = extractZipToFolder(zipContent, path);
113+ }
114+ catch (ZipException e) {}
115+ finally
116+ {
117+ if (! extracted)
118+ throw new Exception (" Error while trying to extract zip to path " ~ path~
119+ " \n Package " ~ packageName~ " repository " ~ repo~ " with branch " ~ requirement.toString~ " download link [" ~ url~ " ]"
120+ );
121+
122+ }
89123 return path;
90124}
91125
0 commit comments