[vhffs-dev] [svn] commit: r268 - /trunk/vhffs-robots/src/fix_quota_repository.pl

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


Author: gradator
Date: Tue Oct 31 05:46:16 2006
New Revision: 268

Log:
Hopla using perl quota module here too :)



Modified:
    trunk/vhffs-robots/src/fix_quota_repository.pl

Modified: trunk/vhffs-robots/src/fix_quota_repository.pl
==============================================================================
--- trunk/vhffs-robots/src/fix_quota_repository.pl (original)
+++ trunk/vhffs-robots/src/fix_quota_repository.pl Tue Oct 31 05:46:16 2006
@@ -38,8 +38,7 @@
 use Vhffs::Robots;
 use Vhffs::Group;
 use Vhffs::Services::Repository;
-
-return -2 if( ! -x "/usr/sbin/setquota" );
+use Quota;
 
 my $vhffs = init Vhffs::Main;
 
@@ -55,13 +54,12 @@
 my $repo;
 my $users;
 my $user;
+my $dev = Quota::getqcarg($vhffs->get_config->get_datadir."/".Vhffs::Constants::REPOSITORYDIR);
 
 foreach $group ( @{$groups} )
 {
 	if( $group->fetch > 0 )
 	{
-		#print $group->{'groupname'}."\n";
-
 		$quota = 0;
 		$blocks = 0;
 		$inodes = 0;
@@ -73,24 +71,28 @@
 			{
 				if( $repo->fetch > 0)
 				{
-					#print "  ".$repo->get_name." -> ".$repo->get_quota." MB\n";
 					$quota += $repo->get_quota;
 					$blocks += $repo->get_quota * 1024;
 					$inodes += $repo->get_quota * 1126400 / 100;
 				}
 			}
 
-			$cmd = "/usr/sbin/setquota -g ".$group->get_gid ." ".$blocks." ".$blocks." ".$inodes." ".$inodes." ".$vhffs->get_config->get_datadir."/".Vhffs::Constants::REPOSITORYDIR;
-			#print $cmd."\n";
-			system( $cmd );
-			Vhffs::Robots::vhffs_log( sprintf( "Update quota for repositories of group %s to %s MB" , $group->get_groupname , $quota ) );
+			unless( Quota::setqlim($dev, $group->get_gid, $blocks, $blocks, $inodes, $inodes, 0, 1) )
+			{
+				Vhffs::Robots::vhffs_log( sprintf( "Update quota for repositories of group %s to %s MB" , $group->get_groupname , $quota ) );
+			}
+			else
+			{
+				printf("Cannot update quota for repositories of group %s, reason: %s\n", $group->get_groupname, Quota::strerr);
+			}
 		}
 		else
 		{
 			# give no space for groups without download repository
-			$cmd = "/usr/sbin/setquota -g ".$group->get_gid ." 1 1 1 1 ".$vhffs->get_config->get_datadir."/".Vhffs::Constants::REPOSITORYDIR;
-			#print $cmd."\n";
-			system( $cmd );
+			if( Quota::setqlim($dev, $group->get_gid, 1, 1, 1, 1, 0, 1) )
+			{
+				printf("Cannot update quota for repositories of group %s, reason: %s\n", $group->get_groupname, Quota::strerr);
+			}
 		}
 	}
 }
@@ -103,9 +105,11 @@
 {
 	if( $user->fetch > 0 )
 	{
-		$cmd = "/usr/sbin/setquota -g ".$user->get_gid ." 1 1 1 1 ".$vhffs->get_config->get_datadir."/".Vhffs::Constants::REPOSITORYDIR;
-		#print $cmd."\n";
-		system( $cmd );
+		# give no space for all primary groups of users
+		if( Quota::setqlim($dev, $user->get_gid, 1, 1, 1, 1, 0, 1) )
+		{
+			printf("Cannot update quota for repositories of primary group of user %s, reason %s\n", $user->get_name, Quota::strerr);
+		}
 	}
 }
 




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