cr.pl: added --noclean option, fix alignment
This commit is contained in:
80
cr.pl
Normal file → Executable file
80
cr.pl
Normal file → Executable file
@@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/perl
|
#!/usr/bin/perl
|
||||||
# TODO: --clean option to cleanup repo accrding to metadata
|
# TODO: implement paths fool proof paths (add trailing backslash if it absent on url and path)
|
||||||
|
#
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings "all";
|
use warnings "all";
|
||||||
@@ -17,16 +18,33 @@ sub urlencode($);
|
|||||||
sub getmetadata();
|
sub getmetadata();
|
||||||
sub help($);
|
sub help($);
|
||||||
sub path_normalize_by_string_manipulation($);
|
sub path_normalize_by_string_manipulation($);
|
||||||
|
sub getfilenames($);
|
||||||
|
|
||||||
|
help(0) unless (defined $ARGV[0]);
|
||||||
help(1) unless (defined $ARGV[1]);
|
help(1) unless (defined $ARGV[1]);
|
||||||
|
|
||||||
help(0) if ($ARGV[0] eq '--help');
|
help(0) if ($ARGV[0] eq '--help');
|
||||||
help(0) if ($ARGV[0] eq '-h');
|
help(0) if ($ARGV[0] eq '-h');
|
||||||
|
|
||||||
|
my $noclean = 0;
|
||||||
|
|
||||||
|
if (defined($ARGV[0]) and $ARGV[0] eq '--noclean') {
|
||||||
|
$noclean = 1;
|
||||||
|
}
|
||||||
|
|
||||||
my $BASEURL = $ARGV[0];
|
my $BASEURL = $ARGV[0];
|
||||||
my $BASEDIR = $ARGV[1];
|
my $BASEDIR = $ARGV[1];
|
||||||
|
|
||||||
my $primaryxmlgz = getmetadata();
|
if ($noclean == 1) {
|
||||||
|
help(1) unless (defined $ARGV[2]);
|
||||||
|
$BASEURL = $ARGV[1];
|
||||||
|
$BASEDIR = $ARGV[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
my @REPOFILES;
|
||||||
|
my @FILES;
|
||||||
|
|
||||||
|
my $primaryxmlgz = getmetadata();
|
||||||
my $fh = new IO::Zlib;
|
my $fh = new IO::Zlib;
|
||||||
my $xmldata = '';
|
my $xmldata = '';
|
||||||
|
|
||||||
@@ -77,14 +95,46 @@ for (my $i = 0; $i < @array; $i++) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exit 0 if ($noclean == 1);
|
||||||
|
|
||||||
|
my $searchpath = $BASEDIR;
|
||||||
|
chop $searchpath;
|
||||||
|
getfilenames($searchpath);
|
||||||
|
my @filesToDelete;
|
||||||
|
|
||||||
|
foreach my $fileOnDisk (@FILES) {
|
||||||
|
my $flag = 0;
|
||||||
|
|
||||||
|
foreach my $fileInXML (@REPOFILES) {
|
||||||
|
if ($fileInXML eq $fileOnDisk) {
|
||||||
|
$flag = 1;
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($flag == 0) {
|
||||||
|
push @filesToDelete, $fileOnDisk;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
foreach my $file (@filesToDelete) {
|
||||||
|
unless (-d $file) {
|
||||||
|
unlink $file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
exit 0;
|
exit 0;
|
||||||
|
|
||||||
sub help($) {
|
sub help($) {
|
||||||
my $rc = shift;
|
my $rc = shift;
|
||||||
my $help = <<'HELP';
|
my $help = <<'HELP';
|
||||||
Usage: cr.pl source destination
|
Usage: cr.pl [--noclean] source destination
|
||||||
|
|
||||||
Where
|
Where
|
||||||
|
--noclean is optional argument, if it specified, no cleanup operation will
|
||||||
|
be performed after rpm downloading complete.
|
||||||
|
|
||||||
Source must be http(s) url which trimmed at repodata folder. If full url is
|
Source must be http(s) url which trimmed at repodata folder. If full url is
|
||||||
http://mirror.yandex.ru/centos/7.4.1708/os/x86_64/repodata/repomd.xml
|
http://mirror.yandex.ru/centos/7.4.1708/os/x86_64/repodata/repomd.xml
|
||||||
source must be given as:
|
source must be given as:
|
||||||
@@ -111,6 +161,8 @@ sub dlfunc(@) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
push @REPOFILES, $savepath;
|
||||||
|
|
||||||
# do not re-download already downloaded rpm packages
|
# do not re-download already downloaded rpm packages
|
||||||
unless ($size == -1) {
|
unless ($size == -1) {
|
||||||
|
|
||||||
@@ -229,4 +281,26 @@ sub path_normalize_by_string_manipulation ($) {
|
|||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub getfilenames($) {
|
||||||
|
my $path = shift;
|
||||||
|
|
||||||
|
opendir (DIR, $path) or return "";
|
||||||
|
my @localfiles;
|
||||||
|
@localfiles =
|
||||||
|
map { $path . '/' . $_ }
|
||||||
|
grep { !/^\.{1,2}$/ }
|
||||||
|
readdir (DIR);
|
||||||
|
@FILES = (@FILES, @localfiles);
|
||||||
|
|
||||||
|
foreach (@localfiles) {
|
||||||
|
next if(-l $_);
|
||||||
|
|
||||||
|
if( -d $_){
|
||||||
|
getfilenames($_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
__END__
|
__END__
|
||||||
|
|||||||
Reference in New Issue
Block a user