From 3614a977f85b272fc2522722b483dc975b3cb0f4 Mon Sep 17 00:00:00 2001 From: Nektarios Katakis Date: Fri, 15 Nov 2019 16:38:41 +0000 Subject: [PATCH] fix: minidlna.conf file permissions after editing Reviewed-by: James Valleroy --- actions/minidlna | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/actions/minidlna b/actions/minidlna index 544fa4c7f..90424f867 100755 --- a/actions/minidlna +++ b/actions/minidlna @@ -21,7 +21,7 @@ Configuration actions for the minidlna server. import argparse from tempfile import mkstemp from shutil import move -from os import fdopen, remove +from os import fdopen, remove, chmod, stat import augeas @@ -82,6 +82,7 @@ def replace_in_config_file(file_path, pattern, subst): Create a temporary minidlna.conf file, replace the media dir config, remove original one and move the temporary file. + Preserve permissions as the original file. """ temp_file, temp_file_path = mkstemp() with fdopen(temp_file, 'w') as new_file: @@ -89,8 +90,10 @@ def replace_in_config_file(file_path, pattern, subst): for line in old_file: new_file.write(line.replace(pattern, subst)) + old_st_mode = stat(file_path).st_mode remove(file_path) move(temp_file_path, file_path) + chmod(file_path, old_st_mode) def main():