Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions source/dub/dub.d
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,14 @@ static this()
}

/// The URL to the official package registry.
enum defaultRegistryURL = "http://code.dlang.org/";
enum fallbackRegistryURL = "https://code-mirror.dlang.io/";
enum defaultRegistryURL = "https://code.dlang.org/";
enum fallbackRegistryURLs = [
// fallback in case of HTTPS problems
"http://code.dlang.org/",
"https://code-mirror.dlang.io/",
"https://code-mirror2.dlang.io/",
"https://dub-registry.herokuapp.com/",
];

/** Returns a default list of package suppliers.

Expand All @@ -80,7 +86,7 @@ PackageSupplier[] defaultPackageSuppliers()
return [
new FallbackPackageSupplier(
new RegistryPackageSupplier(URL(defaultRegistryURL)),
new RegistryPackageSupplier(URL(fallbackRegistryURL))
fallbackRegistryURLs.map!(x => cast(PackageSupplier) new RegistryPackageSupplier(URL(x))).array
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could have stayed with the recursive structure.

fallbackRegistryURLs.reduce!((agg, url) => new FallbackPackageSupplier(agg, new RegistryPackageSupplier(URL(x))))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I thought the "linear" way is more intuitive, but I don't really mind. If you feel strongly the recursive structure, feel free to change it back.

)
];
}
Expand Down
24 changes: 19 additions & 5 deletions source/dub/packagesupplier.d
Original file line number Diff line number Diff line change
Expand Up @@ -292,17 +292,19 @@ class RegistryPackageSupplier : PackageSupplier {

package abstract class AbstractFallbackPackageSupplier : PackageSupplier
{
protected PackageSupplier m_default, m_fallback;
protected PackageSupplier m_default;
protected PackageSupplier[] m_fallbacks;

this(PackageSupplier default_, PackageSupplier fallback)
this(PackageSupplier default_, PackageSupplier[] fallbacks)
{
m_default = default_;
m_fallback = fallback;
m_fallbacks = fallbacks;
}

override @property string description()
{
return format("%s (fallback %s)", m_default.description, m_fallback.description);
import std.algorithm : map;
return format("%s (fallback %s)", m_default.description, m_fallbacks.map!(x => x.description));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker, but this is fairly long and detailed.

==== registry at https://code.dlang.org/ (fallback ["registry at http://code.dlang.org/", "registry at https://code-mirror.dlang.io/", "registry at https://code-mirror2.dlang.io/", "registry at https://dub-registry.herokuapp.com/"]) ====

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, but the PackageSupplier interface currently only supports a description attribute. We could add sth. like location in a follow-up?

}

// Workaround https://issues.dlang.org/show_bug.cgi?id=2525
Expand All @@ -322,7 +324,19 @@ package alias FallbackPackageSupplier = AutoImplement!(AbstractFallbackPackageSu
private template fallback(T, alias func)
{
enum fallback = q{
scope (failure) return m_fallback.%1$s(args);
import std.range : back, dropBackOne;
import dub.internal.vibecompat.core.log : logDebug;
scope (failure)
{
foreach (m_fallback; m_fallbacks.dropBackOne)
{
try
return m_fallback.%1$s(args);
catch(Exception)
logDebug("Package supplier %s failed. Trying next fallback.", m_fallback);
}
return m_fallbacks.back.%1$s(args);
}
return m_default.%1$s(args);
}.format(__traits(identifier, func));
}
Expand Down