From aa31b5d13bf547379e815cbe37cb438895a5e2e4 Mon Sep 17 00:00:00 2001 From: Robert Pengelly Date: Sun, 31 Aug 2025 05:35:57 +0100 Subject: [PATCH] Check if the entry exists before making it --- Makefile.w32 | 2 +- e2cp.c | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Makefile.w32 b/Makefile.w32 index 7f09f4e..0f48bad 100644 --- a/Makefile.w32 +++ b/Makefile.w32 @@ -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 3a5ebaf..283ec2d 100644 --- 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); } -- 2.34.1