summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--methods/mirror.cc11
-rwxr-xr-xtest/integration/test-method-mirror15
2 files changed, 23 insertions, 3 deletions
diff --git a/methods/mirror.cc b/methods/mirror.cc
index 787e4c7d5..5781ebcf0 100644
--- a/methods/mirror.cc
+++ b/methods/mirror.cc
@@ -326,7 +326,11 @@ std::string MirrorMethod::GetMirrorFileURI(std::string const &Message, FetchItem
{
if (APT::String::Startswith(Itm->Uri, uristr))
{
- uristr.erase(uristr.length() - 1); // remove the ending '/'
+ if (::URI uri{uristr}; uri.Path.length() > 1 && APT::String::Endswith(uri.Path, "/"))
+ {
+ uri.Path.erase(uri.Path.length() - 1); // remove the ending '/'
+ uristr = uri;
+ }
auto const colon = uristr.find(':');
if (unlikely(colon == std::string::npos))
continue;
@@ -375,7 +379,10 @@ bool MirrorMethod::URIAcquire(std::string const &Message, FetchItem *Itm) /*{{{*
msgCache[Itm->Uri] = Message;
MirrorListInfo info;
info.state = REQUESTED;
- info.baseuri = mirrorfileuri + '/';
+ if (not APT::String::Endswith(mirrorfileuri, "/"))
+ info.baseuri = mirrorfileuri + '/';
+ else
+ info.baseuri = mirrorfileuri;
auto const colon = info.baseuri.find(':');
if (unlikely(colon == std::string::npos))
return false;
diff --git a/test/integration/test-method-mirror b/test/integration/test-method-mirror
index ce44b86e3..1784e1ecb 100755
--- a/test/integration/test-method-mirror
+++ b/test/integration/test-method-mirror
@@ -124,9 +124,22 @@ msgmsg 'all mirrored via file'
APTARCHIVE="$(readlink -f ./aptarchive)"
sed -i -e "s#mirror+http://localhost:${APTHTTPPORT}#mirror+file:${APTARCHIVE}#" rootdir/etc/apt/sources.list.d/*
testrun '*_localhost_*' '*_aptarchive_mirror.txt.gz_*'
+sed -i -e 's#/mirror\.txt\.gz stable#/mirror.txt stable#' rootdir/etc/apt/sources.list.d/*
+
+mv rootdir/etc/apt/sources.list.d rootdir/etc/apt/sources.list.d.bak
+mkdir rootdir/etc/apt/sources.list.d
+msgmsg 'fail gracefully if mirror uri has no filename'
+echo "deb mirror://localhost:${APTHTTPPORT}/ stable main" > rootdir/etc/apt/sources.list.d/mirrordir.list
+testfailure apt update
+
+msgmsg 'but succeed if it is indeed a mirror list'
+ln -s mirror.txt aptarchive/index.html
+testsuccess apt update
+rm aptarchive/index.html rootdir/etc/apt/sources.list.d/mirrordir.list
+rmdir rootdir/etc/apt/sources.list.d
+mv rootdir/etc/apt/sources.list.d.bak rootdir/etc/apt/sources.list.d
msgmsg 'fallback mirrors are used if needed' 'as usual'
-sed -i -e 's#/mirror\.txt\.gz stable#/mirror.txt stable#' rootdir/etc/apt/sources.list.d/*
echo "http://localhost:${APTHTTPPORT}/failure2 priority:3
http://localhost:${APTHTTPPORT}/redirectme priority:2
http://localhost:${APTHTTPPORT}/failure priority:1" > aptarchive/mirror.txt