Skip to content

Commit 2fd3881

Browse files
committed
Open config file in read&write mode
1 parent b1b2715 commit 2fd3881

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

containers/proxy-squid/uyuni-configure.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@
99
config = yaml.safe_load(source)
1010

1111
# read to existing config file
12-
with open("/etc/squid/squid.conf", "r") as dest:
13-
file_content = dest.read()
14-
15-
# adapt the config file
12+
with open("/etc/squid/squid.conf", "r+") as config_file:
13+
file_content = config_file.read()
1614
file_content = re.sub(r"cache_dir ufs .*", f"cache_dir ufs /var/cache/squid {str(config['max_cache_size_mb'])} 16 256", file_content)
1715
file_content = re.sub(r"access_log .*", "access_log stdio:/proc/self/fd/1 squid", file_content)
18-
19-
# write to file
20-
with open("/etc/squid/squid.conf", "w") as dest:
21-
dest.write(file_content)
16+
# writing back the content
17+
config_file.seek(0,0)
18+
config_file.write(file_content)
19+
config_file.truncate()
2220

2321
# make sure "squid" is the user and group owner of the cache squid path
2422
os.system('chown -R squid:squid /var/cache/squid')

0 commit comments

Comments
 (0)