⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fslock.pm

📁 外国人写的Perl搜索引擎程序
💻 PM
字号:
package KinoSearch::Store::FSLock;use strict;use warnings;use KinoSearch::Util::ToolSet;use base qw( KinoSearch::Store::Lock );BEGIN { __PACKAGE__->init_instance_vars() }use Fcntl qw( :DEFAULT :flock );use File::Spec::Functions qw( catfile );use KinoSearch::Store::FSInvIndex;my $disable_locks = 0;    # placeholder -- locks always enabled for nowsub init_instance {    my $self = shift;    # derive the lockfile's filepath    $self->{lock_name} = catfile(        $KinoSearch::Store::FSInvIndex::LOCK_DIR,  # TODO fix this stupid hack        $self->{invindex}->get_lock_prefix . "-$self->{lock_name}"    );}sub do_obtain {    my $self = shift;    return 1 if $disable_locks;    my $lock_name = $self->{lock_name};    # check for locks created by old processes and remove them    if ( -e $lock_name ) {        open( my $fh, $lock_name ) or confess "Can't open $lock_name: $!";        my $line = <$fh>;        $line =~ /pid: (\d+)/;        my $pid = $1;        close $fh or confess "Can't close '$lock_name': $!";        unless ( kill 0 => $pid ) {            warn "Lockfile looks dead - removing";            unlink $lock_name or confess "Can't unlink '$lock_name: $!";        }    }    # create a lock by creating a lockfile    return        unless sysopen( my $fh, $lock_name, O_CREAT | O_WRONLY | O_EXCL );    # print pid and path to the lock file, using YAML for future compat    print $fh "pid: $$\ninvindex: " . $self->{invindex}->get_path . "\n";    close $fh or confess "Can't close '$lock_name': $!";    # success!    return 1;}sub release {    my $self = shift;    return if $disable_locks;    # release the lock by removing the lockfile from the file system    unlink $self->{lock_name}        or confess("Couldn't unlink file '$self->{lock_name}': $!");}sub is_locked {    # if the lockfile exists, the resource is locked    return ( -e $_[0]->{lock_name} or $disable_locks );}1;__END__=begin devdocs=head1 NAMEKinoSearch::Store::FSLock - lock an FSInvIndex=head1 DESCRIPTIONFile-system-based implementation ofL<KinoSearch::Store::Lock|KinoSearch::Store::Lock>.=head1 COPYRIGHTCopyright 2005-2007 Marvin Humphrey=head1 LICENSE, DISCLAIMER, BUGS, etc.See L<KinoSearch|KinoSearch> version 0.163.=end devdocs=cut

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -