Skip to content

Commit 76c05d9

Browse files
committed
Fixed: Github changes to its repository zip API, better ZIP extract errror message and better validation
1 parent 9b34906 commit 76c05d9

3 files changed

Lines changed: 48 additions & 9 deletions

File tree

source/redub/buildapi.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import redub.package_searching.api;
77

88

99
///vX.X.X
10-
enum RedubVersionOnly = "v1.31.1";
10+
enum RedubVersionOnly = "v1.31.2";
1111
///Redub vX.X.X
1212
enum RedubVersionShort = "Redub "~RedubVersionOnly;
1313
///Redub vX.X.X - Description

source/redub/package_searching/downloader.d

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

3548
string 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-
\nExample 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\tExample of repository with branch usage: \"redub\": {\"version\": \"~master\", \"repository\": \"git+https://github.com/MrcSnm/redub.git\"}"~
55+
"\n\tBranches 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
8197
string 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+
"\nPackage "~packageName~ " repository "~ repo~ " with branch "~ requirement.toString~ " download link [" ~ url~"]"
120+
);
121+
122+
}
89123
return path;
90124
}
91125

source/redub/parsers/json.d

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,11 @@ BuildRequirements parse(JSONValue json, ParseConfig cfg, out BuildConfiguration
334334
version_ = tryStr(value, "version");
335335
repo = tryStr(value, "repository");
336336
visibility = value.tryStr("visibility");
337+
if(repo.length)
338+
{
339+
enforce(version_,
340+
"Dependency named "~depName~" specified the repository "~repo~" but no branch was specified. Specify its branch at \"version\".");
341+
}
337342
enforce(version_ || path,
338343
"Dependency named "~ depName ~
339344
" must contain at least a \"path\" or \"version\" property."

0 commit comments

Comments
 (0)