Handle both old and new style apt repo files

pull/83835/head
Andy Foston 1 year ago
parent c48cc5b913
commit a0dea908ae

@ -488,7 +488,7 @@ class UbuntuSourcesList(SourcesList):
self.module.fail_json(msg="failed to fetch PPA information, error was: %s" % info['msg']) self.module.fail_json(msg="failed to fetch PPA information, error was: %s" % info['msg'])
return json.loads(to_native(response.read())) return json.loads(to_native(response.read()))
def _expand_ppa(self, path): def _expand_ppa(self, path, legacy=False):
ppa = path.split(':')[1] ppa = path.split(':')[1]
ppa_owner = ppa.split('/')[0] ppa_owner = ppa.split('/')[0]
try: try:
@ -496,6 +496,9 @@ class UbuntuSourcesList(SourcesList):
except IndexError: except IndexError:
ppa_name = 'ppa' ppa_name = 'ppa'
if legacy:
line = 'deb %s/%s/%s/ubuntu %s main' % (self.PPA_URI, ppa_owner, ppa_name, self.codename)
else:
keypath = self._get_ppa_keyfile("ubuntu-%s-main" % self.codename, ppa_owner, ppa_name) keypath = self._get_ppa_keyfile("ubuntu-%s-main" % self.codename, ppa_owner, ppa_name)
line = 'deb [signed-by=%s] %s/%s/%s/ubuntu %s main' % (keypath, self.PPA_URI, ppa_owner, ppa_name, self.codename) line = 'deb [signed-by=%s] %s/%s/%s/ubuntu %s main' % (keypath, self.PPA_URI, ppa_owner, ppa_name, self.codename)
return line, ppa_owner, ppa_name return line, ppa_owner, ppa_name
@ -553,8 +556,9 @@ class UbuntuSourcesList(SourcesList):
def add_source(self, line, comment='', file=None): def add_source(self, line, comment='', file=None):
if line.startswith('ppa:'): if line.startswith('ppa:'):
source, ppa_owner, ppa_name = self._expand_ppa(line) source, ppa_owner, ppa_name = self._expand_ppa(line)
legacy_source = self._expand_ppa(line, legacy=True)[0]
if source in self.repos_urls: if source in self.repos_urls or legacy_source in self.repos_urls:
# repository already exists # repository already exists
return return
@ -582,6 +586,9 @@ class UbuntuSourcesList(SourcesList):
def remove_source(self, line): def remove_source(self, line):
if line.startswith('ppa:'): if line.startswith('ppa:'):
source = self._expand_ppa(line)[0] source = self._expand_ppa(line)[0]
# Remove both explicit signed-by and "legancy" repos without the signed-by value set
legacy_source = self._expand_ppa(line, legacy=True)[0]
self._remove_valid_source(legacy_source)
else: else:
source = self._parse(line, raise_if_invalid_or_disabled=True)[2] source = self._parse(line, raise_if_invalid_or_disabled=True)[2]
self._remove_valid_source(source) self._remove_valid_source(source)
@ -601,6 +608,8 @@ class UbuntuSourcesList(SourcesList):
if source_line.startswith('ppa:'): if source_line.startswith('ppa:'):
source, ppa_owner, ppa_name = self._expand_ppa(source_line) source, ppa_owner, ppa_name = self._expand_ppa(source_line)
_repositories.append(source) _repositories.append(source)
source = self._expand_ppa(source_line, legacy=True)
_repositories.append(source)
else: else:
_repositories.append(source_line) _repositories.append(source_line)

Loading…
Cancel
Save