]> git.99rst.org Git - irssi-scripts.irssi.org.git/commitdiff
Properly handle mappings file creation
authormartin f. krafft <redacted>
Wed, 15 Feb 2017 21:14:05 +0000 (22:14 +0100)
committermartin f. krafft <redacted>
Wed, 15 Feb 2017 21:34:44 +0000 (22:34 +0100)
Signed-off-by: martin f. krafft <redacted>
scripts/ctrlact.pl

index 28263ef8e0f70451f19e3f0f3c1908f436f1b592..c35a2c4467778c33b46dcb40f55c651150605aa6 100644 (file)
@@ -370,7 +370,7 @@ sub get_mappings_fh {
                my $ftc = from_data_level($fallback_channel_threshold);
                my $ftq = from_data_level($fallback_query_threshold);
                print $fh <<"EOF";
-# ctrlact mappings file (version:$VERSION)
+# ctrlact mappings file (version: $VERSION)
 #
 # type: window, channel, query
 # server: the server tag (chatnet)
@@ -411,6 +411,7 @@ sub get_mappings_fh {
 # vim:noet:tw=0:ts=16
 EOF
                Irssi::print("ctrlact: created new/empty mappings file: $filename");
+               seek($fh, 0, 0) || croak "Cannot rewind $filename.";
        }
        return $fh;
 }
@@ -419,9 +420,9 @@ sub load_mappings {
        my ($filename) = @_;
        @window_thresholds = @channel_thresholds = @query_thresholds = ();
        my $fh = get_mappings_fh($filename);
-       my $firstline = <$fh>;
+       my $firstline = <$fh> || croak "Cannot read from $filename.";;
        my $version;
-       if ($firstline =~ m/^#+\s+ctrlact mappings file \(version:([\d.]+)\)/) {
+       if ($firstline =~ m/^#+\s+ctrlact mappings file \(version: *([\d.]+)\)/) {
                $version = $1;
        }
        else {
git clone https://git.99rst.org/PROJECT