Skip to content

Commit

Permalink
tools: Use shlex for parsing version.txt
Browse files Browse the repository at this point in the history
This is to guard against quoted values.
  • Loading branch information
krnowak committed Oct 26, 2023
1 parent 8ff4451 commit bdfad35
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions tools/fcl-fetch-version-data.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

import glob
import json
import re
import sys
import shlex
import urllib.request

import yaml
Expand All @@ -27,9 +27,14 @@ def latestVersion(channel = 'stable', board = 'amd64-usr'):
url = 'https://%s.release.flatcar-linux.net/%s/current/version.txt' % (channel, board)
try:
versionTxt = fetch(url)
match = re.findall('FLATCAR_VERSION=(.*)', versionTxt)
if len(match) > 0:
return match[0]
s = shlex.shlex(versionTxt, posix = True, punctuation_chars = '=')
s.whitespace_split = True
for item in s:
if item == 'FLATCAR_VERSION':
items = list(s)
if len(items) < 2 or items[0] != '=':
raise 'malformed version.txt'
return items[1]
except:
return 'unreleased'

Expand Down

0 comments on commit bdfad35

Please sign in to comment.