summaryrefslogtreecommitdiff
path: root/lib/JWebmail/Plugin/ServerSideSessionData.pm
diff options
context:
space:
mode:
authorJannis M. Hoffmann <jannis.hoffmann@rwth-aachen.de>2022-05-01 22:02:37 +0200
committerJannis M. Hoffmann <jannis.hoffmann@rwth-aachen.de>2022-05-01 22:02:37 +0200
commit7c8bd21ccbca8a3166289ab0e5511cc82d2822aa (patch)
tree89c77a638ee2c12f3b3a023562ee222d5a8d6324 /lib/JWebmail/Plugin/ServerSideSessionData.pm
parentc94966aac2f16ca7a6f8c4c8988677515b46a45b (diff)
collection of smaller changes
Diffstat (limited to 'lib/JWebmail/Plugin/ServerSideSessionData.pm')
-rw-r--r--lib/JWebmail/Plugin/ServerSideSessionData.pm30
1 files changed, 15 insertions, 15 deletions
diff --git a/lib/JWebmail/Plugin/ServerSideSessionData.pm b/lib/JWebmail/Plugin/ServerSideSessionData.pm
index d416c00..40772eb 100644
--- a/lib/JWebmail/Plugin/ServerSideSessionData.pm
+++ b/lib/JWebmail/Plugin/ServerSideSessionData.pm
@@ -1,13 +1,13 @@
package JWebmail::Plugin::ServerSideSessionData v1.1.0;
-use Mojo::Base 'Mojolicious::Plugin';
+use Mojo::Base Mojolicious::Plugin;
+
+use Fcntl qw(:DEFAULT :seek);
+use Time::HiRes 'sleep';
use Mojo::JSON qw(decode_json encode_json);
use Mojo::File;
-use Fcntl ':DEFAULT', ':seek';
-use Time::HiRes 'sleep';
-
use constant {
S_KEY => 's3d.key',
@@ -16,11 +16,11 @@ use constant {
ADVANCE_ON_FAILURE => 10, # seconds to retry to acquire the lock
};
+
has 'session_directory';
has 'expiration';
has 'cleanup_interval';
-
-has 'next_cleanup' => 0;
+has _next_cleanup => 0;
# read and potentially update file return bool
@@ -30,8 +30,8 @@ sub _rw_cleanup_file {
my $self = shift;
my $time = shift;
- my $lock_name = $self->session_directory->child(CLEANUP_FILE_NAME . ".lock");
- my $info_name = $self->session_directory->child(CLEANUP_FILE_NAME . ".info");
+ my $lock_name = $self->session_directory->child(CLEANUP_FILE_NAME . '.lock');
+ my $info_name = $self->session_directory->child(CLEANUP_FILE_NAME . '.info');
my ($lock, $ctr, $rmlock);
until (sysopen($lock, $lock_name, O_WRONLY | O_CREAT | O_EXCL)) {
@@ -46,7 +46,7 @@ sub _rw_cleanup_file {
$rmlock = 1;
next;
}
- $self->next_cleanup($time + ADVANCE_ON_FAILURE);
+ $self->_next_cleanup($time + ADVANCE_ON_FAILURE);
return 0;
}
sleep(0.01); # TODO: better spin locking
@@ -60,12 +60,12 @@ sub _rw_cleanup_file {
use autodie;
open(my $info, -e $info_name ? '+<' : '+>', $info_name);
- my $next_time = $info->getline;
- $next_time = 0 unless ($next_time//'') =~ /^\d+$/;
+ my $next_time = $info->getline // '';
+ $next_time = 0 unless $next_time =~ /^\d+$/a;
chomp $next_time;
if ($next_time > $time) {
$info->close;
- $self->next_cleanup($next_time);
+ $self->_next_cleanup($next_time);
return 0;
}
else {
@@ -73,7 +73,7 @@ sub _rw_cleanup_file {
$info->seek(0, SEEK_SET);
$info->say($time + $self->cleanup_interval);
$info->close;
- $self->next_cleanup($time + $self->cleanup_interval);
+ $self->_next_cleanup($time + $self->cleanup_interval);
return 1;
}
};
@@ -86,7 +86,7 @@ sub cleanup_files {
my $self = shift;
my $t = time;
- if ($self->next_cleanup < $t && $self->_rw_cleanup_file($t)) {
+ if ($self->_next_cleanup < $t && $self->_rw_cleanup_file($t)) {
for ($self->session_directory->list->each) {
if ( $_->stat->mtime + $self->expiration < $t ) {
$_->remove;
@@ -127,7 +127,7 @@ sub s3d {
$data->{$key} = $val;
$file->spurt(encode_json $data, "\n");
- return;
+ return $self;
}
else { # get
return defined $key ? $data->{$key} : $data;