Check if the entry exists before making it
authorRobert Pengelly <robertapengelly@hotmail.com>
Sun, 31 Aug 2025 04:35:57 +0000 (05:35 +0100)
committerRobert Pengelly <robertapengelly@hotmail.com>
Sun, 31 Aug 2025 04:35:57 +0000 (05:35 +0100)
Makefile.w32
e2cp.c

index 7f09f4e0264412a6079b9d82621144050ee07806..0f48bad10d02ab0e8528e8c1f86e1da421dce3c8 100644 (file)
@@ -30,4 +30,4 @@ e2md.exe: e2md.c cache.c common.c list.c report.c
 
 e2cp.exe: e2cp.c cache.c common.c list.c report.c
 
-       $(CC) $(CFLAGS) -o $@ $^
\ No newline at end of file
+       $(CC) $(CFLAGS) -o $@ $^
diff --git a/e2cp.c b/e2cp.c
index 3a5ebafa024f0a2ec1b27e708a53dd62a070f23f..283ec2d32bc4e1cd57763274f98e3061dae05fb8 100644 (file)
--- a/e2cp.c
+++ b/e2cp.c
@@ -423,7 +423,7 @@ static int walk_path (struct filesystem *fs, char *dirname) {
 
 }
 
-static void copy_file (struct filesystem *fs, FILE *fp, unsigned long parent, char *fn) {
+static void copy_file (struct filesystem *fs, FILE *fp, unsigned long parent_nod, char *fn) {
 
     unsigned long bytes = 0, timestamp = time (0);
     char *basename = fn, *p;
@@ -432,12 +432,19 @@ static void copy_file (struct filesystem *fs, FILE *fp, unsigned long parent, ch
         basename = (p + 1);
     }
     
+    if (find_entry (fs, parent_nod, basename)) {
+    
+        report_at (program_name, 0, REPORT_ERROR, "'%s' already exists.  Currently replacing files isn't supported.", basename);
+        return;
+    
+    }
+    
     fseek (fp, 0, SEEK_END);
     
     bytes = ftell (fp);
     fseek (fp, 0, SEEK_SET);
     
-    mkfile_fs (fs, parent, basename, fp, bytes, 0, 0, timestamp, timestamp);
+    mkfile_fs (fs, parent_nod, basename, fp, bytes, 0, 0, timestamp, timestamp);
 
 }