]> git.ipfire.org Git - people/stevee/ipfire-2.x.git/commitdiff
ids-functions.pl: Add function to create empty files
authorStefan Schantl <stefan.schantl@ipfire.org>
Fri, 24 Aug 2018 05:37:10 +0000 (07:37 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Fri, 24 Aug 2018 05:37:10 +0000 (07:37 +0200)
This generic function can be used to create any kind of emtpy files -
it just requires the full path and filename to work.

If the specified file exists at calltime, the function will abort
to prevent from overwriting existing files and content.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
config/cfgroot/ids-functions.pl

index cb16e1b49309030e7ef3238f8a1ff2e0c7f5e819..6f7f3ee7ef7eb07857a5982607c13fdf734a70b6 100644 (file)
@@ -355,4 +355,26 @@ sub call_suricatactrl ($) {
        return;
 }
 
+#
+## Function to create a new empty file.
+#
+sub create_empty_file($) {
+       my ($file) = @_;
+
+       # Check if the given file exists.
+       if(-e $file) {
+               # Do nothing to prevent from overwriting existing files.
+               return;
+       }
+
+       # Open the file for writing.
+       open(FILE, ">$file") or die "Could not write to $file. $!\n";
+
+       # Close file handle.
+       close(FILE);
+
+       # Return true.
+       return 1;
+}
+
 1;