mirror of
https://github.com/certbot/certbot.git
synced 2026-05-28 04:34:11 -04:00
Use relative paths for livedir symlinks (#3914)
* Use relative paths for livedir symlinks * switch directory back for the rest of the tests
This commit is contained in:
parent
107851ee9b
commit
27525fb205
2 changed files with 24 additions and 6 deletions
|
|
@ -198,6 +198,10 @@ def lineagename_for_filename(config_filename):
|
|||
"renewal config file name must end in .conf")
|
||||
return os.path.basename(config_filename[:-len(".conf")])
|
||||
|
||||
def _relpath_from_file(archive_dir, from_file):
|
||||
"""Path to a directory from a file"""
|
||||
return os.path.relpath(archive_dir, os.path.dirname(from_file))
|
||||
|
||||
|
||||
class RenewableCert(object):
|
||||
# pylint: disable=too-many-instance-attributes,too-many-public-methods
|
||||
|
|
@ -305,6 +309,13 @@ class RenewableCert(object):
|
|||
return os.path.join(
|
||||
self.cli_config.default_archive_dir, self.lineagename)
|
||||
|
||||
def relative_archive_dir(self, from_file):
|
||||
"""Returns the default or specified archive directory as a relative path
|
||||
|
||||
Used for creating symbolic links.
|
||||
"""
|
||||
return _relpath_from_file(self.archive_dir, from_file)
|
||||
|
||||
@property
|
||||
def is_test_cert(self):
|
||||
"""Returns true if this is a test cert from a staging server."""
|
||||
|
|
@ -331,7 +342,8 @@ class RenewableCert(object):
|
|||
for kind in ALL_FOUR:
|
||||
link = getattr(self, kind)
|
||||
previous_link = get_link_target(link)
|
||||
new_link = os.path.join(self.archive_dir, os.path.basename(previous_link))
|
||||
new_link = os.path.join(self.relative_archive_dir(link),
|
||||
os.path.basename(previous_link))
|
||||
|
||||
os.unlink(link)
|
||||
os.symlink(new_link, link)
|
||||
|
|
@ -856,7 +868,7 @@ class RenewableCert(object):
|
|||
target = dict([(kind, os.path.join(live_dir, kind + ".pem"))
|
||||
for kind in ALL_FOUR])
|
||||
for kind in ALL_FOUR:
|
||||
os.symlink(os.path.join(archive, kind + "1.pem"),
|
||||
os.symlink(os.path.join(_relpath_from_file(archive, target[kind]), kind + "1.pem"),
|
||||
target[kind])
|
||||
with open(target["cert"], "wb") as f:
|
||||
logger.debug("Writing certificate to %s.", target["cert"])
|
||||
|
|
|
|||
|
|
@ -99,10 +99,16 @@ class UpdateLiveSymlinksTest(BaseCertManagerTest):
|
|||
cert_manager.update_live_symlinks(self.cli_config)
|
||||
|
||||
# check that symlinks go where they should
|
||||
for domain in self.domains:
|
||||
for kind in ALL_FOUR:
|
||||
self.assertEqual(os.readlink(self.configs[domain][kind]),
|
||||
archive_paths[domain][kind])
|
||||
prev_dir = os.getcwd()
|
||||
try:
|
||||
for domain in self.domains:
|
||||
for kind in ALL_FOUR:
|
||||
os.chdir(os.path.dirname(self.configs[domain][kind]))
|
||||
self.assertEqual(
|
||||
os.path.realpath(os.readlink(self.configs[domain][kind])),
|
||||
os.path.realpath(archive_paths[domain][kind]))
|
||||
finally:
|
||||
os.chdir(prev_dir)
|
||||
|
||||
|
||||
class CertificatesTest(BaseCertManagerTest):
|
||||
|
|
|
|||
Loading…
Reference in a new issue