From 2b821adb5f8dbd98cdf856865f1b39a3dead5a39 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 31 Dec 2024 14:54:10 +0000 Subject: [PATCH] stripper: Ignore if source files don't exist Signed-off-by: Michael Tremer --- src/libpakfire/stripper.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/libpakfire/stripper.c b/src/libpakfire/stripper.c index 631151c2a..f93025ee6 100644 --- a/src/libpakfire/stripper.c +++ b/src/libpakfire/stripper.c @@ -231,6 +231,29 @@ static int pakfire_stripper_copy_source_file( if (r < 0) goto ERROR; + // Open the source file + src = fopen(srcpath, "r"); + if (!src) { + switch (errno) { + // If the source file does not exist, we cannot copy anything + case ENOENT: + goto ERROR; + + default: + ERROR(stripper->ctx, "Could not open %s: %m\n", filename); + r = -errno; + goto ERROR; + } + } + + // Stat the source file + r = fstat(fileno(src), &st); + if (r < 0) { + ERROR(stripper->ctx, "Could not stat %s: %m\n", filename); + r = -errno; + goto ERROR; + } + // Create all directories r = pakfire_mkparentdir(dstpath, 0755); if (r < 0) @@ -251,22 +274,6 @@ static int pakfire_stripper_copy_source_file( } } - // Open the source file - src = fopen(srcpath, "r"); - if (!src) { - ERROR(stripper->ctx, "Could not open %s: %m\n", filename); - r = -errno; - goto ERROR; - } - - // Stat the source file - r = fstat(fileno(src), &st); - if (r < 0) { - ERROR(stripper->ctx, "Could not stat %s: %m\n", filename); - r = -errno; - goto ERROR; - } - // Copy all content ssize_t bytes_written = sendfile(fileno(dst), fileno(src), 0, st.st_size); if (bytes_written < st.st_size) { -- 2.47.2