mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-04-26 04:45:35 +08:00
remove old and new zonefile paths when removing a zonefile
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user