Re: [OpenWrt-Devel] [PATCH] Updated patch to check multiple instances in subfolders in local repository

2012-04-06 Thread Tathagata Das
Hi,
 I have updated the patch as Philip and Jo-Philipp suggested.

Signed-off-by: Tathagata Das tathag...@alumnux.com

---

diff -Naur a/scripts/download.pl b/scripts/download.pl
--- a/scripts/download.pl   2012-04-05 18:59:13.0 +0530
+++ b/scripts/download.pl   2012-04-06 11:27:12.0 +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;
 
@@ -65,6 +66,7 @@
$mirror =~ s/\/$//;
if( $mirror =~ /^file:\/\// ) {
my $cache = $mirror;
+   my $mylink=;
$cache =~ s/file:\/\///g;
if(system(test -d $cache)) {
print STDERR Wrong local cache directory -$cache-.\n;
@@ -74,7 +76,32 @@
if(! -d $target) {
system(mkdir -p $target/);
}
-   system(cp -vf $cache/$filename $target/$filename.dl) == 0 or 
return;
+   if (open TMPDLS, find $cache -follow -name $filename 
2/dev/null |){
+   my $i = 0;
+   my $link = ;
+   while (defined($link = readline TMPDLS)){
+   chomp $link;
+   $mylink=$link;
+   $i++;
+   if ($i  1) { 
+   print($i or more instances of 
$filename in $cache found . Only one instance allowed.\n);
+   return;
+   }
+   }
+   close TMPDLS;
+   if ($i  1) {
+   print(No instances of $filename found in 
$cache.\n);
+   return;
+   }
+   if ($i == 1){
+   print(Copying $filename from $mylink\n);
+   copy($mylink, $target/$filename.dl);
+   }
+   }
+   else {
+   print(Failed to search for $filename in $cache\n);
+   return;
+   }
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;


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


Re: [OpenWrt-Devel] [PATCH] Updated patch to check multiple instances in subfolders in local repository

2012-04-04 Thread Tathagata Das
Hi,
 I have updated the patch as Philip and Jo-Philipp suggested.

Thanks Philip and Jo-Philipp for your feedback.

Signed-off-by: Tathagata Das tathag...@alumnux.com

---

diff -Naur a/scripts/download.pl b/scripts/download.pl
--- a/scripts/download.pl   2012-04-04 13:19:27.0 +0530
+++ b/scripts/download.pl   2012-04-04 13:20:34.0 +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 {
+   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;


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


Re: [OpenWrt-Devel] [PATCH] Updated patch to check multiple instances in subfolders in local repository

2012-04-04 Thread Philip Prindeville
More comments...


On 4/4/12 3:37 AM, Tathagata Das wrote:
 Hi,
  I have updated the patch as Philip and Jo-Philipp suggested.
 
 Thanks Philip and Jo-Philipp for your feedback.
 
 Signed-off-by: Tathagata Das tathag...@alumnux.com
 
 ---
 
 diff -Naur a/scripts/download.pl b/scripts/download.pl
 --- a/scripts/download.pl 2012-04-04 13:19:27.0 +0530
 +++ b/scripts/download.pl 2012-04-04 13:20:34.0 +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 {
 + 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;
 + }
 + }

Close the file as soon as you're done with it. You're less likely to run out of 
file descriptors.

 + 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;

perldoc Digest::MD5


use Digest::MD5;

my $ctx = Digest::MD5-new;

open(FILE, $target/$filename.dl) || die can't open $target/$filename.dl;
binmode(FILE);
$ctx-addfile(*FILE);
close(FILE);

my $digest = $ctx-hexdigest;
open(DIGEST, $target/$filename.md5sum) || die can't save md5sum for 
$target/$filename.mdsum;
print DIGEST, $digest, \n;
close(DIGEST);



   } else {
   open WGET, wget -t5 --timeout=20 --no-check-certificate 
 $options -O- \$mirror/$filename\ | or die Cannot launch wget.\n;
 
 

___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


Re: [OpenWrt-Devel] [PATCH] Updated patch to check multiple instances in subfolders in local repository

2012-04-04 Thread Jo-Philipp Wich
-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.0 +0530
 +++ b/scripts/download.pl 2012-04-04 13:20:34.0 +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


Re: [OpenWrt-Devel] [PATCH] Updated patch to check multiple instances in subfolders in local repository

2012-04-04 Thread Jo-Philipp Wich
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi Philipp,

in principle I aggree but I've seen Perl distributions without
Digest::MD5 available by default, so shelling out to call md5sum
sounds ok to me.

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

iEYEARECAAYFAk98l1cACgkQdputYINPTPOV/gCgk4Orm9nfGq0mJzBWi6pErMFC
ui0AoJ6YR3buQEQs8/R7sNNRzYBwrOiK
=vIrd
-END PGP SIGNATURE-
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


Re: [OpenWrt-Devel] [PATCH] Updated patch to check multiple instances in subfolders in local repository

2012-04-04 Thread Philip Prindeville
On 4/4/12 12:47 PM, Jo-Philipp Wich wrote:
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1
 
 Hi Philipp,
 
 in principle I aggree but I've seen Perl distributions without
 Digest::MD5 available by default, so shelling out to call md5sum
 sounds ok to me.
 
 ~ Jow

Your call. I'm just trying to cut down on fork/exec pairs.

On my multicore machine doing everything inside the Perl script is 
significantly faster than forking external processes...


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


Re: [OpenWrt-Devel] [PATCH] Updated patch to check multiple instances in subfolders in local repository

2012-04-03 Thread Philip Prindeville
Inline...

On 4/2/12 6:06 AM, Tathagata Das wrote:
 Hi,
  I have modified the patch as John suggested. This patch will only copy a 
 single file from local repository. If more than one instance of the same file 
 exists in the subfolders then it will throw an error. I have used latest 
 trunk (revision 31050) to test this patch.
 
 Thanks John for your feedback.
 
 Signed-off-by: Tathagata Das tathag...@alumnux.com
 
 ---
 
 diff -Naur a/scripts/download.pl b/scripts/download.pl
 --- a/scripts/download.pl 2012-03-05 10:44:02.0 +0530
 +++ b/scripts/download.pl 2012-04-02 17:31:28.0 +0530
 @@ -74,7 +74,18 @@
   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 1 
 temp.dls);

You don't need 1 since '1' is the default.


 + my $lines = `cat temp.dls | wc -l`;

Perl isn't a wrapper for bash. You can slurp a file and get the record count 
without needing 2 extra processes to do so.


 + if ($lines != 1 ) {
 + system(echo Error : Number of instances of $filename 
 in $cache is $lines);
 + system(echo Only one instance allowed.);
 + system(rm -f temp.dls);

You don't need an extra process for this. You can do:

unlink(temp.dls);

instead.


 + return;
 + }
 + else {
 + system(cat temp.dls | xargs -i cp -vf {} 
 $target/$filename.dl);
 + system(rm -f temp.dls);

Ditto.


 + }
   system($md5cmd $target/$filename.dl  
 \$target/$filename.md5sum\ ) == 0 or return;

Why are you quoting filenames in some places but not others?

   } else {
   open WGET, wget -t5 --timeout=20 --no-check-certificate 
 $options -O- \$mirror/$filename\ | or die Cannot launch wget.\n;
 
 
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH] Updated patch to check multiple instances in subfolders in local repository

2012-04-02 Thread Tathagata Das
Hi,
 I have modified the patch as John suggested. This patch will only copy a 
single file from local repository. If more than one instance of the same file 
exists in the subfolders then it will throw an error. I have used latest trunk 
(revision 31050) to test this patch.

Thanks John for your feedback.

Signed-off-by: Tathagata Das tathag...@alumnux.com

---

diff -Naur a/scripts/download.pl b/scripts/download.pl
--- a/scripts/download.pl   2012-03-05 10:44:02.0 +0530
+++ b/scripts/download.pl   2012-04-02 17:31:28.0 +0530
@@ -74,7 +74,18 @@
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 1 
temp.dls);
+   my $lines = `cat temp.dls | wc -l`;
+   if ($lines != 1 ) {
+   system(echo Error : Number of instances of $filename 
in $cache is $lines);
+   system(echo Only one instance allowed.);
+   system(rm -f temp.dls);
+   return;
+   }
+   else {
+   system(cat temp.dls | xargs -i cp -vf {} 
$target/$filename.dl);
+   system(rm -f temp.dls);
+   }
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;


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


Re: [OpenWrt-Devel] [PATCH] Updated patch to check multiple instances in subfolders in local repository

2012-04-02 Thread Jo-Philipp Wich
While the existing perl code isn't the best either, yours is extremely
inefficient, you should rework it using native functions.

 + system(find $cache -follow -name $filename 2/dev/null 1 
 temp.dls);
perldoc -f open

 + my $lines = `cat temp.dls | wc -l`;
perldoc -f length, perldoc perlvar

 + if ($lines != 1 ) {
($lines  1) ?

 + system(echo Error : Number of instances of $filename 
 in $cache is $lines);
 + system(echo Only one instance allowed.);
perldoc -f print, perldoc -f warn

 + system(rm -f temp.dls);
perldoc -f unlink

 + return;
 + }
 + else {
 + system(cat temp.dls | xargs -i cp -vf {} 
 $target/$filename.dl);
perldoc -f open, perldoc -f readline
Also google useless use of cat.

 + system(rm -f temp.dls);
perldoc -f unlink

 + }
   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
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel