+ // already retrieved
+ if (distSession.itemExists(distPath))
+ return distSession.getNode(distPath);
+
+ // find mirror
+ List<String> urlBases = null;
+ String uriPrefix = null;
+ uriPrefixes: for (String uriPref : mirrors.keySet()) {
+ if (uri.startsWith(uriPref)) {
+ if (mirrors.get(uriPref).size() > 0) {
+ urlBases = mirrors.get(uriPref);
+ uriPrefix = uriPref;
+ break uriPrefixes;
+ }
+ }
+ }
+ if (urlBases == null)
+ try {
+ return loadUrlToPath(uri, distSession, distPath);
+ } catch (FileNotFoundException e) {
+ throw new SlcException("Cannot download " + uri, e);
+ }
+
+ // try to download
+ for (String urlBase : urlBases) {
+ String relativePath = uri.substring(uriPrefix.length());
+ String url = urlBase + relativePath;
+ try {
+ return loadUrlToPath(url, distSession, distPath);
+ } catch (FileNotFoundException e) {
+ if (log.isDebugEnabled())
+ log.debug("Cannot download" + url
+ + ", trying another mirror");
+ }
+ }