New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
debian: Support downloading from a mirror in addition to having it locally #12
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f07b25a
Support downloading files from a mirror, instead of having them local
iainlane c892185
Try to use HTTP/FTP directly so that we can set timeouts
iainlane 022bd8d
Try to use std.stdio
iainlane debde9b
Be less noisy
8ee45b3
Add a helper to find the first {xz, bz2, gz} file we can, and downloa…
468c394
utils: Use rawWrite when downloading
9b3070f
immutable things are immutable auto by default
1cecf19
Move downloadIfNecessary to the debian backend
6d97045
Add a documentation comment
5545404
Make downloadFile support retrying on timeouts
26b5fd0
utils: Add pre and postconditions to downloadFile
dd61afa
Remove a comment asking for something which now happens
5494463
debian/utils.d: Update docs for downloadIfNecessary
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* | ||
| * Copyright (C) 2016 Canonical Ltd | ||
| * Author(s): Iain Lane <iain@orangesquash.org.uk> | ||
| * | ||
| * Licensed under the GNU Lesser General Public License Version 3 | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Lesser General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the license, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This software is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public License | ||
| * along with this software. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| module ag.backend.debian.utils; | ||
|
|
||
| import std.string; | ||
|
|
||
| import ag.logging; | ||
| import ag.utils : downloadFile, isRemote; | ||
|
|
||
| /** | ||
| * If prefix is remote, download the first of (prefix + suffix).{xz,bz2,gz}, | ||
| * otherwise check if any of (prefix + suffix).{xz,bz2,gz} exists. | ||
| * | ||
| * Returns: Path to the file, which is guaranteed to exist. | ||
| * | ||
| * Params: | ||
| * prefix = First part of the address, i.e. | ||
| * "http://ftp.debian.org/debian/" or "/srv/mirrors/debian/" | ||
| * destPrefix = If the file is remote, the directory to save it under, | ||
| * which is created if necessary. | ||
| * suffix = the rest of the address, so that (prefix + | ||
| * suffix).format({xz,bz2,gz}) is a full path or URL, i.e. | ||
| * "dists/unstable/main/binary-i386/Packages.%s". The suffix must | ||
| * contain exactly one "%s"; this function is only suitable for | ||
| * finding `.xz`, `.bz2` and `.gz` files. | ||
| */ | ||
| immutable (string) downloadIfNecessary (const string prefix, | ||
| const string destPrefix, | ||
| const string suffix) | ||
| { | ||
| import std.net.curl; | ||
| import std.path; | ||
|
|
||
| immutable exts = ["xz", "bz2", "gz"]; | ||
| foreach (ref ext; exts) { | ||
| immutable fileName = format (buildPath (prefix, suffix), ext); | ||
| immutable destFileName = format (buildPath (destPrefix, suffix), ext); | ||
|
|
||
| if (fileName.isRemote) { | ||
| try { | ||
| /* This should use download(), but that doesn't throw errors */ | ||
| downloadFile (fileName, destFileName); | ||
|
|
||
| return destFileName; | ||
| } catch (CurlException ex) { | ||
| logDebug ("Couldn't download: %s", ex.msg); | ||
| } | ||
| } else { | ||
| if (std.file.exists (fileName)) | ||
| return fileName; | ||
| } | ||
| } | ||
|
|
||
| /* all extensions failed, so we failed */ | ||
| throw new Exception (format ("Couldn't obtain any file matching %s", | ||
| buildPath (prefix, suffix))); | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't that be
downloadIfNecessary? Otherwise we might unnecessarily download multiple times...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
downloadFileitself avoids re-downloading if the dest exists. Here I have the entire path, so it's easier to download directly;downloadIfNecessaryis easier to use if you're constructing the path yourself from a base and suffix.(That reminds me that
downloadIfNecessary's doc comment needs expanding...)