-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi, you can optimize out the temporary dl file.

> diff -Naur a/scripts/download.pl b/scripts/download.pl
> --- a/scripts/download.pl     2012-04-04 13:19:27.000000000 +0530
> +++ b/scripts/download.pl     2012-04-04 13:20:34.000000000 +0530
> @@ -9,6 +9,7 @@
>  use strict;
>  use warnings;
>  use File::Basename;
> +use File::Copy;
>  
>  @ARGV > 2 or die "Syntax: $0 <target dir> <filename> <md5sum> [<mirror> 
> ...]\n";
>  
> @@ -74,7 +75,29 @@
>               if(! -d $target) {
>                       system("mkdir -p $target/");
>               }
> -             system("cp -vf $cache/$filename $target/$filename.dl") == 0 or 
> return;
> +             system("find $cache -follow -name $filename 2>/dev/null >> 
> temp.dls");
> +             open TMPDLS,"temp.dls"  and do {

if (open TMPDLS, "find $cache -follow -name $filename 2>/dev/null |")
{
    while (defined(my $link = readline TMPDLS))
    {
        chomp $link;

        ...
    }

    close TMPDLS;
}
else
{
    ...
}

> +                     my $i = 0;
> +                     my $link = "";
> +                     while (<TMPDLS>) {
> +                             $link = $_;
> +                             chomp $link;
> +                             $i++;
> +                             if ($i > 1) { 
> +                                     print("$i or more instances of 
> $filename in $cache found . Only one instance allowed.\n");
> +                                     last;
> +                             }
> +                     }
> +                     if ($i < 1) {
> +                             print("No instances of $filename found in 
> $cache.\n");
> +                     }
> +                     if ($i == 1){
> +                             print("Copying $link.\n");
> +                             copy($link, "$target/$filename.dl");
> +                     }
> +                     unlink("temp.dls") or print("Falied to delete the 
> temporary file\n");
> +                     close TMPDLS;
> +             };
>               system("$md5cmd $target/$filename.dl > 
> \"$target/$filename.md5sum\" ") == 0 or return;
>       } else {
>               open WGET, "wget -t5 --timeout=20 --no-check-certificate 
> $options -O- \"$mirror/$filename\" |" or die "Cannot launch wget.\n";

~ Jow
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk98lusACgkQdputYINPTPPIiACfRHpFOQXsTyfuAwdlCakMTvsw
fw8AoJyEKxTaM8TggfFn+okuNMuaPszw
=iEZ9
-----END PGP SIGNATURE-----
_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to