From fa3545c092522a43517669387ad2a953a4a2fd04 Mon Sep 17 00:00:00 2001 From: Simon Krauter Date: Fri, 10 Oct 2014 23:24:28 +0200 Subject: Raise exception on adding a non-existent file to a zip archive --- lib/impure/zipfiles.nim | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/impure/zipfiles.nim b/lib/impure/zipfiles.nim index 1726449d8..63b8a843d 100644 --- a/lib/impure/zipfiles.nim +++ b/lib/impure/zipfiles.nim @@ -56,6 +56,11 @@ proc addFile*(z: var TZipArchive, dest, src: string) = ## Adds the file `src` to the archive `z` with the name `dest`. `dest` ## may contain a path that will be created. assert(z.mode != fmRead) + if not fileExists(src): + var e: ref EIO + new(e) + e.msg = "File does not exist" + raise e var zipsrc = zip_source_file(z.w, src, 0, -1) if zipsrc == nil: #echo("Dest: " & dest) -- cgit 1.4.1-2-gfad0 From d526e051c516ced3533f421637ca2ea3c11e03db Mon Sep 17 00:00:00 2001 From: Simon Krauter Date: Sat, 11 Oct 2014 00:20:49 +0200 Subject: Code more cleaner --- lib/impure/zipfiles.nim | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/impure/zipfiles.nim b/lib/impure/zipfiles.nim index 63b8a843d..b9f89dda0 100644 --- a/lib/impure/zipfiles.nim +++ b/lib/impure/zipfiles.nim @@ -57,10 +57,7 @@ proc addFile*(z: var TZipArchive, dest, src: string) = ## may contain a path that will be created. assert(z.mode != fmRead) if not fileExists(src): - var e: ref EIO - new(e) - e.msg = "File does not exist" - raise e + raise newException(EIO, "File '" & src & "' does not exist") var zipsrc = zip_source_file(z.w, src, 0, -1) if zipsrc == nil: #echo("Dest: " & dest) -- cgit 1.4.1-2-gfad0