]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
edit-util: minor cleanups
authorMike Yuan <me@yhndnzj.com>
Sat, 11 Mar 2023 14:52:39 +0000 (22:52 +0800)
committerMike Yuan <me@yhndnzj.com>
Sun, 12 Mar 2023 16:40:15 +0000 (00:40 +0800)
Reuse unlink_and_free() and avoid unnecessary
call to rmdir()

src/shared/edit-util.c

index ba1f4128a0d771cc05d3ab53f42848516b65ae52..734c06601ba01d68e1b84effa700817a098095f3 100644 (file)
@@ -24,10 +24,7 @@ void edit_file_context_done(EditFileContext *context) {
         assert(context);
 
         FOREACH_ARRAY(i, context->files, context->n_files) {
-                if (i->temp) {
-                        (void) unlink(i->temp);
-                        free(i->temp);
-                }
+                unlink_and_free(i->temp);
 
                 if (context->remove_parent) {
                         _cleanup_free_ char *parent = NULL;
@@ -35,9 +32,8 @@ void edit_file_context_done(EditFileContext *context) {
                         r = path_extract_directory(i->path, &parent);
                         if (r < 0)
                                 log_debug_errno(r, "Failed to extract directory from '%s', ignoring: %m", i->path);
-
-                        /* No need to check if the dir is empty, rmdir does nothing if it is not the case. */
-                        (void) rmdir(parent);
+                        else /* No need to check if the dir is empty, rmdir does nothing if it is not the case. */
+                            (void) rmdir(parent);
                 }
 
                 free(i->path);