]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - config/updxlrator/download
clamav: Move database directory to /var partition
[people/pmueller/ipfire-2.x.git] / config / updxlrator / download
index ff86155b5538b546d42ca25969174bbef4315da4..afa6e6cb9172d206a64c3f720b35425c3ae88448 100644 (file)
@@ -30,7 +30,6 @@ my $unique=0;
 my $mirror=1;
 
 my %dlinfo=();
-my $wgetContinueFlag="";
 
 my $vendorid  = $ARGV[0]; if (!defined($vendorid)  || $vendorid  eq '') { exit; }
 my $sourceurl = $ARGV[1]; if (!defined($sourceurl) || $sourceurl eq '') { exit; }
@@ -49,8 +48,7 @@ $vendorid =~ tr/A-Z/a-z/;
 unless (-d "$repository/download/$vendorid")
 {
        system("mkdir -p $repository/download/$vendorid");
-       system("chown -R nobody.squid $repository/download/$vendorid");
-       system("chmod 775 $repository/download/$vendorid");
+       chmod 0775, "$repository/download/$vendorid";
 }
 
 if($restartdl == 0)
@@ -58,16 +56,15 @@ if($restartdl == 0)
        # this is a new download
        exit if (-e "$repository/download/$vendorid/$updatefile");
 
-       # dotzball: Why is this necessary?
+       # hinder multiple downloads from starting simultaneously. Create empty "lock" file.
+       # TODO: Another thread may sneak in between these two commands - so not fool-proof, but good enough?
        system("touch $repository/download/$vendorid/$updatefile");
-       $wgetContinueFlag = "-nc";
 
 }
 else
 {
        # this is a restart of a previous (unfinished) download
        # -> continue download
-       $wgetContinueFlag = "-c";
        &writelog("Continue download: $updatefile");
 }
 
@@ -109,7 +106,7 @@ if ($xlratorsettings{'MAX_DOWNLOAD_RATE'} eq '')
 {
        &writelog("Retrieving file for local cache: $updatefile");
 } else {
-       &writelog("Retrieving file for local cache at max. " . $xlratorsettings{'MAX_DOWNLOAD_RATE'} . " kBit/s: $updatefile");
+       &writelog("Retrieving file for local cache at max. " . $xlratorsettings{'MAX_DOWNLOAD_RATE'} . " kbit/s: $updatefile");
 }
 
 $ENV{'http_proxy'} = $proxysettings{'UPSTREAM_PROXY'};
@@ -134,7 +131,9 @@ unless($restartdl)
 {
        # this is a new download
        # -> download from scratch
-       unlink "$repository/download/$vendorid/$updatefile";
+
+       #already exited earlier if the file existed, and afterwards created this empty "lock", so if not empty now, another thread is already downloading it.
+       exit if ( -s "$repository/download/$vendorid/$updatefile" );
        unlink "$repository/download/$vendorid/$updatefile.info";
 }
 
@@ -148,7 +147,7 @@ $dlinfo{'REMOTESIZE'} = $remote_size;
 $dlinfo{'STATUS'} = "1";
 &UPDXLT::writehash("$repository/download/$vendorid/$updatefile.info", \%dlinfo);
 
-my $cmd = "$UPDXLT::wget $login $dlrate --user-agent=\"$UPDXLT::useragent\" -q -P $repository/download/$vendorid $wgetContinueFlag $sourceurl";
+my $cmd = "$UPDXLT::wget $login $dlrate --user-agent=\"$UPDXLT::useragent\" -q -P $repository/download/$vendorid --continue $sourceurl";
 
 $_ = system("$cmd");
 $ENV{'http_proxy'} = '';
@@ -159,16 +158,14 @@ if ($_ == 0)
 
        unless (-d "$repository/$vendorid")
        {
-  system("mkdir -p $repository/$vendorid");
-               system("chown -R nobody.squid $repository/$vendorid");
-               system("chmod 775 $repository/$vendorid");
+               system("mkdir -p $repository/$vendorid");
+               chmod 0775, "$repository/$vendorid";
        }
 
        unless (-d "$repository/$vendorid/$uuid")
        {
                system("mkdir -p $repository/$vendorid/$uuid");
-               system("chown -R nobody.squid $repository/$vendorid/$uuid");
-               system("chmod 775 $repository/$vendorid/$uuid");
+               chmod 0775, "$repository/$vendorid/$uuid";
        }
 
        &writelog("Moving file to the cache directory: $vendorid/$uuid");
@@ -183,8 +180,15 @@ if ($_ == 0)
        &UPDXLT::setcachestatus("$repository/$vendorid/$uuid/checkup.log",time);
        &UPDXLT::setcachestatus("$repository/$vendorid/$uuid/access.log",time);
 
-       system("chown -R nobody.squid $repository/$vendorid/$uuid/*");
-       system("chmod 775 $repository/$vendorid/$uuid/*");
+       # Update permissions of all files in the download directory.
+       my @files = (
+               "$repository/$vendorid/$uuid/source.url",
+               "$repository/$vendorid/$uuid/status",
+               "$repository/$vendorid/$uuid/checkup.log",
+               "$repository/$vendorid/$uuid/access.log",
+               "$repository/$vendorid/$uuid/$updatefile"
+       );
+       chmod 0664, @files;
 
        unlink ("$repository/download/$vendorid/$updatefile.info");