mirror of
https://github.com/certbot/certbot.git
synced 2026-07-28 08:45:19 +02:00
Allow existing but empty archive and live dir
This commit is contained in:
@@ -21,6 +21,7 @@ Certbot adheres to [Semantic Versioning](https://semver.org/).
|
||||
* Stop asking interactively if the user would like to add a redirect.
|
||||
* `mock` dependency is now conditional on Python 2 in all of our packages.
|
||||
* Deprecate certbot-auto on Gentoo, macOS, and FreeBSD.
|
||||
* Allow existing but empty archive and live dir to be used when creating new lineage.
|
||||
|
||||
### Fixed
|
||||
|
||||
|
||||
@@ -1007,18 +1007,18 @@ class RenewableCert(interfaces.RenewableCert):
|
||||
lineagename = lineagename_for_filename(config_filename)
|
||||
archive = full_archive_path(None, cli_config, lineagename)
|
||||
live_dir = _full_live_path(cli_config, lineagename)
|
||||
if os.path.exists(archive):
|
||||
if os.path.exists(archive) and (not os.path.isdir(archive) or os.listdir(archive)):
|
||||
config_file.close()
|
||||
raise errors.CertStorageError(
|
||||
"archive directory exists for " + lineagename)
|
||||
if os.path.exists(live_dir):
|
||||
if os.path.exists(live_dir) and (not os.path.isdir(live_dir) or os.listdir(live_dir)):
|
||||
config_file.close()
|
||||
raise errors.CertStorageError(
|
||||
"live directory exists for " + lineagename)
|
||||
filesystem.mkdir(archive)
|
||||
filesystem.mkdir(live_dir)
|
||||
logger.debug("Archive directory %s and live "
|
||||
"directory %s created.", archive, live_dir)
|
||||
for i in (archive, live_dir):
|
||||
if not os.path.exists(i):
|
||||
filesystem.makedirs(i)
|
||||
logger.debug("Creating directory %s.", i)
|
||||
|
||||
# Put the data into the appropriate files on disk
|
||||
target = {kind: os.path.join(live_dir, kind + ".pem") for kind in ALL_FOUR}
|
||||
|
||||
@@ -610,17 +610,25 @@ class RenewableCertTests(BaseRenewableCertTest):
|
||||
self.config.renewal_configs_dir, "the-lineage.com-0001.conf")))
|
||||
self.assertTrue(os.path.exists(os.path.join(
|
||||
self.config.live_dir, "the-lineage.com-0001", "README")))
|
||||
# Allow write to existing but empty dir
|
||||
filesystem.mkdir(os.path.join(self.config.default_archive_dir, "the-lineage.com-0002"))
|
||||
result = storage.RenewableCert.new_lineage(
|
||||
"the-lineage.com", b"cert3", b"privkey3", b"chain3", self.config)
|
||||
self.assertTrue(os.path.exists(os.path.join(
|
||||
self.config.live_dir, "the-lineage.com-0002", "README")))
|
||||
self.assertTrue(filesystem.check_mode(result.key_path, 0o600))
|
||||
# Now trigger the detection of already existing files
|
||||
filesystem.mkdir(os.path.join(
|
||||
self.config.live_dir, "the-lineage.com-0002"))
|
||||
shutil.copytree(os.path.join(self.config.live_dir, "the-lineage.com"),
|
||||
os.path.join(self.config.live_dir, "the-lineage.com-0003"))
|
||||
self.assertRaises(errors.CertStorageError,
|
||||
storage.RenewableCert.new_lineage, "the-lineage.com",
|
||||
b"cert3", b"privkey3", b"chain3", self.config)
|
||||
filesystem.mkdir(os.path.join(self.config.default_archive_dir, "other-example.com"))
|
||||
b"cert4", b"privkey4", b"chain4", self.config)
|
||||
shutil.copytree(os.path.join(self.config.live_dir, "the-lineage.com"),
|
||||
os.path.join(self.config.live_dir, "other-example.com"))
|
||||
self.assertRaises(errors.CertStorageError,
|
||||
storage.RenewableCert.new_lineage,
|
||||
"other-example.com", b"cert4",
|
||||
b"privkey4", b"chain4", self.config)
|
||||
"other-example.com", b"cert5",
|
||||
b"privkey5", b"chain5", self.config)
|
||||
# Make sure it can accept renewal parameters
|
||||
result = storage.RenewableCert.new_lineage(
|
||||
"the-lineage.com", b"cert2", b"privkey2", b"chain2", self.config)
|
||||
|
||||
Reference in New Issue
Block a user