From: Michael Tremer Date: Tue, 25 May 2021 20:28:31 +0000 (+0000) Subject: pakfire: bind: Support binding files, too X-Git-Tag: 0.9.28~1285^2~67 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e96df731ecefacc2159084166a6cb78f471b35da;p=pakfire.git pakfire: bind: Support binding files, too Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index 6b382e951..373c0916d 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -967,6 +967,7 @@ int __pakfire_make_path(Pakfire pakfire, char* dst, size_t length, const char* p } PAKFIRE_EXPORT int pakfire_bind(Pakfire pakfire, const char* src, const char* dst, int flags) { + struct stat st; char mountpoint[PATH_MAX]; if (!dst) @@ -978,15 +979,38 @@ PAKFIRE_EXPORT int pakfire_bind(Pakfire pakfire, const char* src, const char* ds DEBUG(pakfire, "Mounting %s to %s\n", src, mountpoint); - // Does the source exist? - r = pakfire_mkdir(src, 0); - if (r && errno != EEXIST) - return r; + r = stat(src, &st); + if (r < 0) { + ERROR(pakfire, "Could not stat %s: %s\n", src, strerror(errno)); + return 1; + } - // Make sure the directory exists - r = pakfire_mkdir(mountpoint, 0); - if (r && errno != EEXIST) - return r; + // Make sure the mountpoint exists + switch (st.st_mode & S_IFMT) { + case S_IFDIR: + r = pakfire_mkdir(mountpoint, 0); + if (r && errno != EEXIST) + return r; + break; + + case S_IFREG: + case S_IFLNK: + // Make parent directory + r = pakfire_mkparentdir(mountpoint, 0); + if (r) + return r; + + // Create a file + FILE* f = fopen(mountpoint, "w"); + if (!f) + return 1; + fclose(f); + break; + + default: + errno = ENOTSUP; + return 1; + } // Perform mount return __mount(pakfire, src, mountpoint, NULL, flags|MS_BIND, NULL);