From 6b0fd2ca99606db63a344031d6a425e604143076 Mon Sep 17 00:00:00 2001 From: Robert Pengelly Date: Mon, 28 Oct 2024 18:08:15 +0000 Subject: [PATCH] Copy as specified filename --- mcopy.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/mcopy.c b/mcopy.c index b4d13f9..8f11136 100644 --- a/mcopy.c +++ b/mcopy.c @@ -562,6 +562,59 @@ int main (int argc, char **argv) { zone_map = INODE_MAP + s_imap_blocks; zone_off = first_data_zone - 1; + if (nb_files >= 2) { + + char *path = files[nb_files - 1]; + char *p; + + if (path[0] == ':' && path[1] == ':') { + + path += 2; + + if (nb_files > 2) { + + report_at (program_name, 0, REPORT_ERROR, "cannot copy multiple files to %s", path); + return EXIT_FAILURE; + + } + + if (root) { + + report_at (program_name, 0, REPORT_WARNING, "root '%s' is ignored, using output path instead", root); + + free (root); + root = 0; + + } + + if ((p = strrchr (path, '/'))) { + + *p = '\0'; + + if (!(parent_ino = walk_path (path))) { + return EXIT_FAILURE; + } + + path = (p + 1); + + } + + if ((fp = fopen (files[0], "rb")) == NULL) { + + report_at (program_name, 0, REPORT_ERROR, "failed to open '%s' for reading", files[0]); + return EXIT_FAILURE; + + } + + copy_file (fp, parent_ino, path); + + fclose (fp); + return (get_error_count () > 0) ? EXIT_FAILURE : EXIT_SUCCESS; + + } + + } + if (root) { if (!(parent_ino = walk_path (root))) { -- 2.34.1