repart: add --append-fstab parameter (#37238)

If --generate-fstab=PATH is used, there is the possibility that the
fstab file already exists, making systemd-repart fail.

This commit will add a new --append-fstab= parameter, that will read
the file and merge it with the new generated content.  Using the
comments, the command can separate the automatic-generated section from
the user-provided section, allowing for the next append the replacement
only of the automatic-generated section, keeping the user one.
This commit is contained in:
Luca Boccassi
2025-05-20 14:49:43 +01:00
committed by GitHub
4 changed files with 137 additions and 3 deletions
+40
View File
@@ -1383,6 +1383,46 @@ char* find_line_startswith(const char *haystack, const char *needle) {
return p + strlen(needle);
}
char* find_line(const char *haystack, const char *needle) {
char *p;
assert(haystack);
assert(needle);
/* Finds the first line in 'haystack' that match the specified string. Returns a pointer to the
* beginning of the line */
p = find_line_startswith(haystack, needle);
if (!p)
return NULL;
if (*p == 0 || strchr(NEWLINE, *p))
return p - strlen(needle);
return NULL;
}
char* find_line_after(const char *haystack, const char *needle) {
char *p;
assert(haystack);
assert(needle);
/* Finds the first line in 'haystack' that match the specified string. Returns a pointer to the
* next line after it */
p = find_line_startswith(haystack, needle);
if (!p)
return NULL;
if (*p == 0)
return p;
if (strchr(NEWLINE, *p))
return p + 1;
return NULL;
}
bool version_is_valid(const char *s) {
if (isempty(s))
return false;
+2
View File
@@ -279,6 +279,8 @@ char* strdupcspn(const char *a, const char *reject);
})
char* find_line_startswith(const char *haystack, const char *needle);
char* find_line(const char *haystack, const char *needle);
char* find_line_after(const char *haystack, const char *needle);
bool version_is_valid(const char *s);