Plugin Directory

Changeset 662741


Ignore:
Timestamp:
02/03/2013 09:30:59 AM (13 years ago)
Author:
6Scan
Message:

Added a lock to prevent race conditions

Location:
6scan-backup/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • 6scan-backup/trunk/6scan.php

    r652989 r662741  
    55Description: 6Scan Backup goes beyond existing backup plugins, easily and automatically creating backups of your site and securely storing them in the cloud.
    66Author: 6Scan
    7 Version: 3.0.1
     7Version: 3.0.2
    88Author URI: http://www.6scan.com
    99*/
  • 6scan-backup/trunk/admin/includes/common.php

    r652989 r662741  
    44    die( 'No direct access allowed' );
    55
    6 define ( 'SIXSCAN_VERSION' ,                            '3.0.1.0' );
     6define ( 'SIXSCAN_VERSION' ,                            '3.0.2.0' );
    77define ( 'SIXSCAN_HTACCESS_VERSION' ,                   '1' );
    88
  • 6scan-backup/trunk/modules/signatures/notice.php

    r570559 r662741  
    11<?php
     2
     3define('SIXSCAN_LOCK_EXPIRATION_SECONDS'    , 60 );
     4define('SIXSCAN_LOCK_FILE_NAME'             , sys_get_temp_dir() . '/__6scan_lock__.dat' );
     5
     6function sixscan_get_lock() {
     7    if ( file_exists( SIXSCAN_LOCK_FILE_NAME ) ){       
     8        $lock_creation_date = @filemtime( SIXSCAN_LOCK_FILE_NAME );     
     9        if ( @time() - SIXSCAN_LOCK_EXPIRATION_SECONDS > $lock_creation_date ){
     10            unlink( SIXSCAN_LOCK_FILE_NAME );           
     11        }
     12        else{
     13            return FALSE;   /* Lock is not yet open */
     14        }
     15    }
     16   
     17    /* Sleep 2-10 ms and then check if file does not exist. If other proccess has created the file during this sleep - fail */
     18    usleep ( rand( 2,30 ) * 1000 );
     19
     20    if ( file_exists( SIXSCAN_LOCK_FILE_NAME ) ){
     21        return FALSE;
     22    }
     23    else{
     24        file_put_contents( SIXSCAN_LOCK_FILE_NAME , '__lock__');   
     25    }
     26    return TRUE;
     27}
     28
     29function sixscan_release_lock(){
     30    unlink( SIXSCAN_LOCK_FILE_NAME );
     31}
    232
    333$wp_load_location = sixscan_notice_find_wp_load_location();
     
    151181/* Update signatures, if needed */
    152182if ( isset( $_REQUEST[ SIXSCAN_NOTICE_UPDATE_NAME ] ) && ( $_REQUEST[ SIXSCAN_NOTICE_UPDATE_NAME ] == 1 ) ){
    153     $error_list .= sixscan_signatures_update_request_total( $site_id ,  $api_token );
     183    if ( sixscan_get_lock() ){
     184        $error_list .= sixscan_signatures_update_request_total( $site_id ,  $api_token );
     185        sixscan_release_lock();
     186    }
     187    else{
     188        $error_list .= 'Failed getting lock. Try later';
     189    }
    154190}
    155191
  • 6scan-backup/trunk/readme.txt

    r659703 r662741  
    11=== 6Scan Backup ===
    22Contributors: 6Scan
    3 Version: 3.0.1
     3Version: 3.0.2
    44Tags: backup, automatic backup, cloud, online, secured, restore, recovery
    55Requires at least: 3.0.0
Note: See TracChangeset for help on using the changeset viewer.