docker-mailserver / docker-mailserver/docker-mailserver
[TODO]: Check and replace existing sed substitute statements with sedfile wrapper
@casperklein is already working on this.
Since Jun 9, 2024.
- Dominant language
- Shell
- Stars
- 18.9k
- Forks
- 2k
- Avg merge
- 5h 15m
- Merged PRs (30d)
- 28
Description
Subject
Something else that requires developers attention
Description
Description
This task is available for anyone that wants to tackle it.
sed substitution statements like sed -i 's/foo/bar/' somefile fail silently, when foo is not found.
This can lead to problems, when a file changed and the search pattern is not found anymore. If there is no explicit test for that, this bug will be unnoticed, until someone reports a problem, that is later tracked down to a sed statement, which no longer took place anymore.
Solution
The wrapper sedfile can replace sed -i [<other options>] <pattern> <file> statements. It checks the file before and after the substitution attempt. If no change is detected, it fails.
More information:
# Wrapper for 'sed -i': fail if file was not modified by sed and container was not restarted.
# Error output is suppressed, when container is restarted to avoid harmless error messages.
# Use "--strict" as first parameter, to fail regardless of the container state (fresh or restarted).
# When to use sedfile?
# Is a file change optional? --> use regular 'sed -i'
# Is a file change expected? --> use 'sedfile --strict -i'
# Is a file change only on the first container run expected? --> use 'sedfile -i'
Example
# Old
sed -i 's/^discard-all-mails=true/discard-all-mails=false/' important.config
# New
sedfile -i 's/^discard-all-mails=true/discard-all-mails=false/' important.config
Todo
Evaluate all sed substitution statements and check, if an sedfile wrapper usage makes sense.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.