mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-20 07:53:01 +02:00
ids-functions.pl: Add function to create empty files
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>
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user