diff options
author | Mike Yuan <me@yhndnzj.com> | 2023-02-25 21:02:17 +0800 |
---|---|---|
committer | Mike Yuan <me@yhndnzj.com> | 2023-03-11 02:01:00 +0800 |
commit | 9a11b4f953f8fdd68aa407a4e4f31670fa789e7c (patch) | |
tree | 8472445483f82aee5500d8ade4ac1cc32cbed081 /src/shared/edit-util.h | |
parent | fa2413dd57bb594b846ee4cfb97d338e59ec5639 (diff) | |
download | systemd-9a11b4f953f8fdd68aa407a4e4f31670fa789e7c.tar.gz |
edit-util: introduce EditFileContext
This is a rather large change which moves
the add and install logic into edit-util.
We store an EditFile array and the number of
elements, along with the edit markers used in
temporary files and whether to remove the parent
directories of the target files if they're empty
in an EditFileContext object.
Call edit_files_add() to add an file to edit,
and do_edit_files_and_install() to do the actual
editing (through create_edit_temp_file(),
run_editor() and trim_edit_markers()).
After that, edit_file_context_done() can be used
to destroy the object.
Diffstat (limited to 'src/shared/edit-util.h')
-rw-r--r-- | src/shared/edit-util.h | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/shared/edit-util.h b/src/shared/edit-util.h index b20c09e896..7b705060e4 100644 --- a/src/shared/edit-util.h +++ b/src/shared/edit-util.h @@ -5,21 +5,28 @@ typedef struct EditFile { char *path; - char *tmp; + char *original_path; + char **comment_paths; + char *temp; unsigned line; } EditFile; -void edit_file_free_all(EditFile **ef); +typedef struct EditFileContext { + EditFile *files; + size_t n_files; + const char *marker_start; + const char *marker_end; + bool remove_parent; +} EditFileContext; -int create_edit_temp_file( - const char *target_path, - const char *original_path, - char * const *comment_paths, - const char *marker_start, - const char *marker_end, - char **ret_temp_filename, - unsigned *ret_edit_line); +void edit_file_context_done(EditFileContext *context); + +bool edit_files_contains(const EditFileContext *context, const char *path); -int run_editor(const EditFile *files); +int edit_files_add( + EditFileContext *context, + const char *path, + const char *original_path, + char * const *comment_paths); -int trim_edit_markers(const char *path, const char *marker_start, const char *marker_end); +int do_edit_files_and_install(EditFileContext *context); |