[vhffs-dev] [820] Add a robot to update quota used by users in the vhffs database

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 820
Author:   gradator
Date:     2007-08-30 02:44:07 +0000 (Thu, 30 Aug 2007)

Log Message:
-----------
Add a robot to update quota used by users in the vhffs database

Modified Paths:
--------------
    trunk/vhffs-robots/Makefile.am
    trunk/vhffs-robots/src/group_getquota.pl

Added Paths:
-----------
    trunk/vhffs-robots/src/user_getquota.pl


Modified: trunk/vhffs-robots/Makefile.am
===================================================================
--- trunk/vhffs-robots/Makefile.am	2007-08-30 02:34:53 UTC (rev 819)
+++ trunk/vhffs-robots/Makefile.am	2007-08-30 02:44:07 UTC (rev 820)
@@ -65,6 +65,7 @@
 	src/user_delete.pl \
 	src/user_group.pl \
 	src/user_setquota.pl \
+	src/user_getquota.pl \
 	src/web_create.pl \
 	src/web_delete.pl \
 	src/web_refused.pl \

Modified: trunk/vhffs-robots/src/group_getquota.pl
===================================================================
--- trunk/vhffs-robots/src/group_getquota.pl	2007-08-30 02:34:53 UTC (rev 819)
+++ trunk/vhffs-robots/src/group_getquota.pl	2007-08-30 02:44:07 UTC (rev 820)
@@ -40,30 +40,28 @@
 use Vhffs::Robots;
 use Vhffs::Group;
 
-
 my $vhffs = init Vhffs::Main;
 
-Vhffs::Robots::lock( $vhffs , "getquota" );
+Vhffs::Robots::lock( $vhffs , "getquotagroup" );
 
 my $groups = Vhffs::Group::getall( $vhffs , Vhffs::Constants::ACTIVATED );
-my $group;
-my $blocks;
-my $used;
 my $dev = Quota::getqcarg($vhffs->get_config->get_datadir);
 
-foreach $group ( @$groups ) {
-	($blocks,undef,undef,undef,undef,undef,undef,undef) = Quota::query($dev, $group->get_gid, 1);
-    if(defined($blocks)) {
-        $used = ($blocks + 1024 - ($blocks % 1024)) / 1024;
-        if($group->get_quota_used() != $used) {
-            $group->set_quota_used( $used );
-            if( $group->commit > 0 ) {
-    			Vhffs::Robots::vhffs_log( sprintf( "Update quota used for group %s set %s" , $group->get_groupname , $used ) , $vhffs);
-		    }
-	    }   
-    }
+foreach my $group ( @$groups ) {
+
+	(my $blocks,undef,undef,undef,undef,undef,undef,undef) = Quota::query($dev, $group->get_gid, 1);
+
+	if(defined($blocks)) {
+		my $used = ($blocks + 1024 - ($blocks % 1024)) / 1024;
+		if($group->get_quota_used() != $used) {
+			$group->set_quota_used( $used );
+			if( $group->commit > 0 ) {
+				Vhffs::Robots::vhffs_log( sprintf( "Update quota used for group %s set %s" , $group->get_groupname , $used ) , $vhffs);
+			}
+		}   
+	}
 }
 
-Vhffs::Robots::unlock( $vhffs , "getquota" );
+Vhffs::Robots::unlock( $vhffs , "getquotagroup" );
 
 exit 0;

Added: trunk/vhffs-robots/src/user_getquota.pl
===================================================================
--- trunk/vhffs-robots/src/user_getquota.pl	                        (rev 0)
+++ trunk/vhffs-robots/src/user_getquota.pl	2007-08-30 02:44:07 UTC (rev 820)
@@ -0,0 +1,68 @@
+#!%PERL%
+# Copyright (c) vhffs project and its contributors
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without 
+# modification, are permitted provided that the following conditions 
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright 
+#   notice, this list of conditions and the following disclaimer.
+#2. Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in 
+#   the documentation and/or other materials provided with the 
+#   distribution.
+#3. Neither the name of vhffs nor the names of its contributors 
+#   may be used to endorse or promote products derived from this 
+#   software without specific prior written permission.
+#
+#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+#"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
+#LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
+#FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+#COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+#INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
+#BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
+#LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
+#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
+# POSSIBILITY OF SUCH DAMAGE.
+
+require 5.004;
+use strict;
+use POSIX;
+use locale;
+use Locale::gettext;
+use Quota;
+use lib '%VHFFS_LIB_DIR%';
+use Vhffs::Main;
+use Vhffs::Robots;
+use Vhffs::Group;
+
+my $vhffs = init Vhffs::Main;
+
+Vhffs::Robots::lock( $vhffs , "getquotauser" );
+
+my $dev = Quota::getqcarg($vhffs->get_config->get_datadir);
+
+my $users = Vhffs::User::getall( $vhffs , Vhffs::Constants::ACTIVATED );
+foreach my $user ( @$users )  {
+
+	my $group = $user->get_group;
+	(my $blocks,undef,undef,undef,undef,undef,undef,undef) = Quota::query($dev, $group->get_gid, 1);
+
+	if(defined($blocks))  {
+		my $used = ($blocks + 1024 - ($blocks % 1024)) / 1024;
+		if($group->get_quota_used() != $used)  {
+			$group->set_quota_used( $used );
+			if( $group->commit > 0 )  {
+    				Vhffs::Robots::vhffs_log( sprintf( "Update quota used for user %s set %s" , $user->get_username , $used ) , $vhffs);
+			}
+		}   
+	}
+}
+
+Vhffs::Robots::unlock( $vhffs , "getquotauser" );
+
+exit 0;


Property changes on: trunk/vhffs-robots/src/user_getquota.pl
___________________________________________________________________
Name: svn:executable
   + *


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/