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
8 changes: 7 additions & 1 deletion source/dub/dub.d
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ static this()

/// The URL to the official package registry.
enum defaultRegistryURL = "http://code.dlang.org/";
enum fallbackRegistryURL = "https://code-mirror.dlang.io/";
Copy link
Contributor

Choose a reason for hiding this comment

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

It would make sense to make this an array (this week will I hopefully finally get around setting up a stable mirror myself).

(http://alpha.dub.pm has been around since a while is an active mirror as well, but we use this VM as a pure staging server to preview PRs, hence I don't consider this as stable.)

Copy link
Contributor

Choose a reason for hiding this comment

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

this week will I hopefully finally get around setting up a stable mirror myself).

GitHub didn't send my review, so I finally got around setting up a stable mirror myself:

-> https://code-mirror2.dlang.io

Heroku Deploy is a bit more difficult to setup due to vibe-d/vibe.d#1785, but I will get around this as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

Heroku Deploy is a bit more difficult to setup due to vibe-d/vibe.d#1785, but I will get around this as well.

-> https://dub-registry.herokuapp.com/

With dlang/dub-registry#231 setting up a local mirror should be absolutely easy (and doesn't even require a CLI nor money).

Copy link
Member Author

Choose a reason for hiding this comment

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

http://alpha.dub.pm/ says bad gateway btw.


/** Returns a default list of package suppliers.

Expand All @@ -76,7 +77,12 @@ enum defaultRegistryURL = "http://code.dlang.org/";
PackageSupplier[] defaultPackageSuppliers()
{
logDiagnostic("Using dub registry url '%s'", defaultRegistryURL);
return [new RegistryPackageSupplier(URL(defaultRegistryURL))];
return [
new FallbackPackageSupplier(
new RegistryPackageSupplier(URL(defaultRegistryURL)),
new RegistryPackageSupplier(URL(fallbackRegistryURL))
)
];
Copy link
Member

Choose a reason for hiding this comment

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

Why not simply return an array of the two? The intent is already that later array entries act as fallbacks to the earlier ones.

Copy link
Member Author

Choose a reason for hiding this comment

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

To avoid duplicates, e.g. in dub search and to correctly deal with user-facing error reporting. The current mechanism adds another registry which can be used e.g. to serve private projects, very different use-case than a mirror registry which is expected to serve identical projects.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hope that the documentation on FallbackPackageRegistry is good enough @s-ludwig.

}


Expand Down
38 changes: 38 additions & 0 deletions source/dub/packagesupplier.d
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import std.datetime;
import std.exception;
import std.file;
import std.string : format;
import std.typecons : AutoImplement;
import std.zip;

// TODO: Could drop the "best package" behavior and let retrievePackage/
Expand Down Expand Up @@ -266,4 +267,41 @@ class RegistryPackageSupplier : PackageSupplier {
}
}

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

this(PackageSupplier default_, PackageSupplier fallback)
{
m_default = default_;
m_fallback = fallback;
}

override @property string description()
{
return format("%s (fallback %s)", m_default.description, m_fallback.description);
}

// Workaround https://issues.dlang.org/show_bug.cgi?id=2525
abstract override Version[] getVersions(string package_id);
abstract override void fetchPackage(Path path, string package_id, Dependency dep, bool pre_release);
abstract override Json fetchPackageRecipe(string package_id, Dependency dep, bool pre_release);
abstract override SearchResult[] searchPackages(string query);
}

/**
Combines two package suppliers and uses the second as fallback to handle failures.

Assumes that both registries serve the same packages (--mirror).
*/
package alias FallbackPackageSupplier = AutoImplement!(AbstractFallbackPackageSupplier, fallback);

private template fallback(T, alias func)
{
enum fallback = q{
scope (failure) return m_fallback.%1$s(args);
return m_default.%1$s(args);
}.format(__traits(identifier, func));
}

private enum PackagesPath = "packages";