Copy as specified filename
authorRobert Pengelly <robertapengelly@hotmail.com>
Mon, 28 Oct 2024 18:08:15 +0000 (18:08 +0000)
committerRobert Pengelly <robertapengelly@hotmail.com>
Mon, 28 Oct 2024 18:08:15 +0000 (18:08 +0000)
mcopy.c

diff --git a/mcopy.c b/mcopy.c
index b4d13f9069317827e702fba37d2901caeaff47b4..8f111363c8e3cf67308a456db210292b34b32268 100644 (file)
--- 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))) {