]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/IMAPTracker.pm
get rid of unnecessary bytes::length usage
[public-inbox.git] / lib / PublicInbox / IMAPTracker.pm
index fe8135823840de7b3f6099658ddbf12307f3ee6d..2fd66440df04ee540f5ce2f96e6e749d44a2e49e 100644 (file)
@@ -39,20 +39,12 @@ sub dbh_new ($) {
        $dbh;
 }
 
-sub get_last ($;$) {
-       my ($self, $validity) = @_;
-       my $sth;
-       if (defined $validity) {
-               $sth = $self->{dbh}->prepare_cached(<<'', undef, 1);
-SELECT uid_validity, uid FROM imap_last WHERE url = ? AND uid_validity = ?
-
-               $sth->execute($self->{url}, $validity);
-       } else {
-               $sth = $self->{dbh}->prepare_cached(<<'', undef, 1);
+sub get_last ($) {
+       my ($self) = @_;
+       my $sth = $self->{dbh}->prepare_cached(<<'', undef, 1);
 SELECT uid_validity, uid FROM imap_last WHERE url = ?
 
-               $sth->execute($self->{url});
-       }
+       $sth->execute($self->{url});
        $sth->fetchrow_array;
 }
 
@@ -70,25 +62,22 @@ VALUES (?, ?, ?)
 }
 
 sub new {
-       my ($class, $url, $dbname) = @_;
+       my ($class, $url) = @_;
 
-       unless (defined($dbname)) {
-               # original name for compatibility with old setups:
-               $dbname = PublicInbox::Config->config_dir() . '/imap.sqlite3';
+       # original name for compatibility with old setups:
+       my $dbname = PublicInbox::Config->config_dir() . '/imap.sqlite3';
 
-               # use the new XDG-compliant name for new setups:
-               if (!-f $dbname) {
-                       $dbname = ($ENV{XDG_DATA_HOME} //
-                                       (($ENV{HOME} // '/nonexistent').
-                                        '/.local/share')) .
-                               '/public-inbox/imap.sqlite3';
-               }
+       # use the new XDG-compliant name for new setups:
+       if (!-f $dbname) {
+               $dbname = ($ENV{XDG_DATA_HOME} //
+                       (($ENV{HOME} // '/nonexistent').'/.local/share')) .
+                       '/public-inbox/imap.sqlite3';
        }
        if (!-f $dbname) {
                require File::Path;
-               require File::Basename;
                require PublicInbox::Spawn;
-               File::Path::mkpath(File::Basename::dirname($dbname));
+               my ($dir) = ($dbname =~ m!(.*?/)[^/]+\z!);
+               File::Path::mkpath($dir);
                open my $fh, '+>>', $dbname or die "failed to open $dbname: $!";
                PublicInbox::Spawn::nodatacow_fd(fileno($fh));
        }