remove old and new zonefile paths when removing a zonefile

This commit is contained in:
Jude Nelson
2018-07-06 13:47:41 -04:00
parent 6bac9087bc
commit 5af4311c63

View File

@@ -39,18 +39,19 @@ def _read_atlas_zonefile( zonefile_path, zonefile_hash ):
Read and verify an atlas zone file
"""
with open(zonefile_path, "r") as f:
with open(zonefile_path, "rb") as f:
data = f.read()
# sanity check
if not verify_zonefile( data, zonefile_hash ):
log.debug("Corrupt zonefile '%s'" % zonefile_hash)
return None
if zonefile_hash is not None:
if not verify_zonefile( data, zonefile_hash ):
log.debug("Corrupt zonefile '%s'" % zonefile_hash)
return None
return data
def get_atlas_zonefile_data( zonefile_hash, zonefile_dir ):
def get_atlas_zonefile_data( zonefile_hash, zonefile_dir, check=True ):
"""
Get a serialized cached zonefile from local disk
Return None if not found
@@ -63,7 +64,11 @@ def get_atlas_zonefile_data( zonefile_hash, zonefile_dir ):
if not os.path.exists( zfp ):
continue
res = _read_atlas_zonefile(zfp, zonefile_hash)
if check:
res = _read_atlas_zonefile(zfp, zonefile_hash)
else:
res = _read_atlas_zonefile(zfp, None)
if res:
return res
@@ -159,7 +164,7 @@ def store_atlas_zonefile_data( zonefile_data, zonefile_dir ):
os.makedirs(zonefile_dir_path)
try:
with open( zonefile_path, "w" ) as f:
with open( zonefile_path, "wb" ) as f:
f.write(zonefile_data)
f.flush()
os.fsync(f.fileno())
@@ -180,7 +185,6 @@ def remove_atlas_zonefile_data( zonefile_hash, zonefile_dir ):
if not os.path.exists(zonefile_dir):
return True
zonefile_hash = get_zonefile_data_hash( zonefile_data )
zonefile_path = atlas_zonefile_path( zonefile_dir, zonefile_hash )
zonefile_path_legacy = atlas_zonefile_path_legacy( zonefile_dir, zonefile_hash )
@@ -192,7 +196,6 @@ def remove_atlas_zonefile_data( zonefile_hash, zonefile_dir ):
os.unlink(zonefile_path)
except:
log.error("Failed to unlink zonefile %s (%s)" % (zonefile_hash, zonefile_path))
return False
return True