mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-04-29 10:10:19 +00:00
fix: minidlna.conf file permissions after editing
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
ef5f5a21de
commit
3614a977f8
@ -21,7 +21,7 @@ Configuration actions for the minidlna server.
|
|||||||
import argparse
|
import argparse
|
||||||
from tempfile import mkstemp
|
from tempfile import mkstemp
|
||||||
from shutil import move
|
from shutil import move
|
||||||
from os import fdopen, remove
|
from os import fdopen, remove, chmod, stat
|
||||||
|
|
||||||
import augeas
|
import augeas
|
||||||
|
|
||||||
@ -82,6 +82,7 @@ def replace_in_config_file(file_path, pattern, subst):
|
|||||||
Create a temporary minidlna.conf file,
|
Create a temporary minidlna.conf file,
|
||||||
replace the media dir config,
|
replace the media dir config,
|
||||||
remove original one and move the temporary file.
|
remove original one and move the temporary file.
|
||||||
|
Preserve permissions as the original file.
|
||||||
"""
|
"""
|
||||||
temp_file, temp_file_path = mkstemp()
|
temp_file, temp_file_path = mkstemp()
|
||||||
with fdopen(temp_file, 'w') as new_file:
|
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:
|
for line in old_file:
|
||||||
new_file.write(line.replace(pattern, subst))
|
new_file.write(line.replace(pattern, subst))
|
||||||
|
|
||||||
|
old_st_mode = stat(file_path).st_mode
|
||||||
remove(file_path)
|
remove(file_path)
|
||||||
move(temp_file_path, file_path)
|
move(temp_file_path, file_path)
|
||||||
|
chmod(file_path, old_st_mode)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user