Skip to content
Merged
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
2 changes: 1 addition & 1 deletion knife
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function find_latest_snapshot() {
local current="$(date -d '-1 day' +%Y-%m-%d)"
local tmp=$(mktemp)
local q=$(date -d "$current" +"year=%Y&month=%m")
if curl -fs "https://snapshot.debian.org/archive/debian/?$q" | grep -ohE "([0-9]+T[0-9]+Z)" > $tmp; then
if curl -fs "https://snapshot.debian.org/archive/${type}/?$q" | grep -ohE "([0-9]+T[0-9]+Z)" > $tmp; then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The regex used to identify snapshot timestamps can be made more robust by specifying the exact format (YYYYMMDDTHHMMSSZ). The current pattern [0-9]+T[0-9]+Z is quite loose and could potentially match other strings in the HTML. Additionally, using curl -fSs instead of curl -fs is recommended as it will display error messages on stderr if the request fails, which aids in debugging while still remaining silent on success. The -h flag for grep is also redundant when reading from a pipe.

    if curl -fSs "https://snapshot.debian.org/archive/${type}/?$q" | grep -oE "[0-9]{8}T[0-9]{6}Z" > "$tmp"; then

# same logic as above, find the newest snapshot that isn't "today"
today=$(date +"%Y%m%dT")
cat $tmp | grep -v $today | tail -n1
Expand Down
Loading