mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-09-01 14:55:10 +00:00
Implement code review comments.
This commit is contained in:
@@ -2164,8 +2164,15 @@ def write_profile(profile, is_attachment=False):
|
|||||||
|
|
||||||
serialize_options = {'METADATA': True, 'is_attachment': is_attachment}
|
serialize_options = {'METADATA': True, 'is_attachment': is_attachment}
|
||||||
profile_string = serialize_profile(split_to_merged(aa), profile, serialize_options)
|
profile_string = serialize_profile(split_to_merged(aa), profile, serialize_options)
|
||||||
with open(prof_filename, 'w') as file: # Keep this context simple: don't want to corrupt file.
|
with NamedTemporaryFile('w', suffix='~', delete=False, dir=profile_dir) as newprof:
|
||||||
file.write(profile_string)
|
if os.path.exists(prof_filename):
|
||||||
|
shutil.copymode(prof_filename, newprof.name)
|
||||||
|
else:
|
||||||
|
# permission_600 = stat.S_IRUSR | stat.S_IWUSR # Owner read and write
|
||||||
|
# os.chmod(newprof.name, permission_600)
|
||||||
|
pass
|
||||||
|
newprof.write(profile_string)
|
||||||
|
os.rename(newprof.name, prof_filename)
|
||||||
|
|
||||||
if profile in changed:
|
if profile in changed:
|
||||||
changed.pop(profile)
|
changed.pop(profile)
|
||||||
|
@@ -677,8 +677,9 @@ class AppArmorEasyProfile:
|
|||||||
|
|
||||||
if not isinstance(policy, bytes):
|
if not isinstance(policy, bytes):
|
||||||
policy = policy.encode('utf-8')
|
policy = policy.encode('utf-8')
|
||||||
with open(out_fn, "wb") as f:
|
with NamedTemporaryFile('wb', prefix='aa-easyprof', suffix='~', delete=False) as f:
|
||||||
f.write(policy)
|
f.write(policy)
|
||||||
|
os.rename(f.name, out_fn)
|
||||||
|
|
||||||
def gen_manifest(self, params):
|
def gen_manifest(self, params):
|
||||||
'''Take params list and output a JSON file'''
|
'''Take params list and output a JSON file'''
|
||||||
|
Reference in New Issue
Block a user