AtomicSoft.com Add power to your website!
Home Products Services Support Free
EasyData/SQL
easy-to-use web interface for SQL databases with countless features
AtomicDesk
help desk, FAQ, knowledge base, live support chat - all in one product
Custom programming
Installation
Documentation
HelpDesk
Libraries
Join our newsletter for information on software updates and new releases. You may unsubscribe at any time.



Click here to download plain text source code.

# subroutine name: GetFileLock
# Locks a file on flock-disabled systems like Win9x, so that no one
# else can get to it while it is being accessed.
# It checks for the existance of a lock file and if it finds it, it
# waits until the lock file disappears, but not more than 20 sec.
# After the lock file is gone, it opens the lock file up itself.
#
# Input:
#      $lock_file = filename to use as a temporary lock file
#
# Global variables used:
#    $no_flock - disable flock or not
#    %LOCK_HANDLES - hash of locked file handles
sub GetFileLock {
    if ($no_flock) {
        my ($lock_file) = @_;
        my $endtime = time + 10;
    
        my $delta = 20/86400; # 20 seconds
    
        if (-e $lock_file && -M $lock_file > $delta) {
            unlink($lock_file);
        }
    
        while (-e $lock_file && time < $endtime) {
            sleep(1);  # Wait 1 sec.
        }
        local *LOCK_FILE;
        $LOCK_HANDLES{$lock_file}=*LOCK_FILE;
        # Create lock file
        open(LOCK_FILE, ">$lock_file") or
            die("Error in subroutine GetFileLock: Can't open $lock_file. Reason: $!");
    }
}
 
Copyright © 1999-2007 Atomicsoft Ltd. All Rights Reserved.