Browse Source

Fix bug where adding the first contact did not create a new contacts file

master
Jonathan "Duke" Leto 6 years ago
parent
commit
8bdcd5edd0
  1. 10
      lib/Hush/Contact.pm

10
lib/Hush/Contact.pm

@ -1,6 +1,7 @@
package Hush::Contact;
use strict;
use warnings;
use lib 'lib';
use Hush::Util qw/barf is_valid_zaddr/;
use Data::Dumper;
use File::Spec::Functions;
@ -25,7 +26,13 @@ sub contact {
my $chain = "hush";
my $contacts_file = catdir($HUSHLIST_CONFIG_DIR,"$chain-contacts.txt");
if (-e $contacts_file) {
unless (-e $contacts_file) {
# first contact being added, create the file
open my $fh, ">>", $contacts_file or barf "Could not create contacts file $contacts_file ! : $!";
print $fh "";
close $fh;
}
my %contacts = read_file( $contacts_file ) =~ /^(z[a-z0-9]+) (.*)$/mgi ;
# TODO: check if zaddr OR nickname exists
@ -37,7 +44,6 @@ sub contact {
print $fh "$zaddr $name\n";
close $fh;
}
}
},
"rm" => sub {
my ($cmd,$name,$zaddr) = @ARGV;

Loading…
Cancel
Save