diff options
Diffstat (limited to 'lib/LXRng/Repo/Plain')
-rw-r--r-- | lib/LXRng/Repo/Plain/Directory.pm | 45 | ||||
-rw-r--r-- | lib/LXRng/Repo/Plain/File.pm | 51 | ||||
-rw-r--r-- | lib/LXRng/Repo/Plain/Iterator.pm | 29 |
3 files changed, 125 insertions, 0 deletions
diff --git a/lib/LXRng/Repo/Plain/Directory.pm b/lib/LXRng/Repo/Plain/Directory.pm new file mode 100644 index 0000000..8d7e701 --- /dev/null +++ b/lib/LXRng/Repo/Plain/Directory.pm @@ -0,0 +1,45 @@ +package LXRng::Repo::Plain::Directory; + +use strict; + +use base qw(LXRng::Repo::Directory); + +sub new { + my ($class, $name, $path, $stat) = @_; + + $name =~ s,(.)/*$,$1/,; + $path =~ s,/*$,/,; + return bless({name => $name, path => $path, stat => $stat}, $class); +} + +sub time { + my ($self) = @_; + + return $$self{'stat'}[9]; +} + +sub size { + my ($self) = @_; + + return ''; +} + +sub contents { + my ($self) = @_; + + my (@dirs, @files); + my ($dir, $node); + opendir($dir, $$self{'path'}) or die("Can't open ".$$self{'path'}.": $!"); + while (defined($node = readdir($dir))) { + next if $node =~ /^\.|~$|\.orig$/; + next if $node eq 'CVS'; + + push(@files, LXRng::Repo::Plain::File->new($$self{'name'}.$node, + $$self{'path'}.$node)); + } + closedir($dir); + + return sort { ref($a) cmp ref($b) || $$a{'name'} cmp $$b{'name'} } @files; +} + +1; diff --git a/lib/LXRng/Repo/Plain/File.pm b/lib/LXRng/Repo/Plain/File.pm new file mode 100644 index 0000000..cf2d6d5 --- /dev/null +++ b/lib/LXRng/Repo/Plain/File.pm @@ -0,0 +1,51 @@ +package LXRng::Repo::Plain::File; + +use strict; + +use base qw(LXRng::Repo::File); +use Fcntl; + +sub new { + my ($class, $name, $path) = @_; + + my @stat = stat($path); + + return undef unless @stat; + + return LXRng::Repo::Plain::Directory->new($name, $path, \@stat) if -d _; + + return bless({name => $name, path => $path, stat => \@stat}, $class); +} + +sub time { + my ($self) = @_; + + return $$self{'stat'}[9]; +} + +sub size { + my ($self) = @_; + + return $$self{'stat'}[7]; +} + +sub phys_path { + my ($self) = @_; + + return $$self{'path'}; +} + +sub revision { + my ($self) = @_; + + return $self->time.'.'.$self->size; +} + +sub handle { + my ($self) = @_; + + sysopen(my $handle, $self->phys_path, O_RDONLY) or die($!); + return $handle; +} + +1; diff --git a/lib/LXRng/Repo/Plain/Iterator.pm b/lib/LXRng/Repo/Plain/Iterator.pm new file mode 100644 index 0000000..b086860 --- /dev/null +++ b/lib/LXRng/Repo/Plain/Iterator.pm @@ -0,0 +1,29 @@ +package LXRng::Repo::Plain::Iterator; + +use strict; +use LXRng::Repo::Plain; + +sub new { + my ($class, $dir) = @_; + + return bless({dir => $dir, stack => [], nodes => [$dir->contents]}, $class); +} + +sub next { + my ($self) = @_; + + while (@{$$self{'nodes'}} == 0) { + return undef unless @{$$self{'stack'}}; + $$self{'nodes'} = pop(@{$$self{'stack'}}); + } + + my $node = shift(@{$$self{'nodes'}}); + if ($node->isa('LXRng::Repo::Directory')) { + push(@{$$self{'stack'}}, $$self{'nodes'}); + $$self{'nodes'} = [$node->contents]; + return $self->next; + } + return $node; +} + +1; |