<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl -w
# This file was preprocessed, do not edit!


package Debconf::DbDriver::DirTree;
use strict;
use Debconf::Log qw(:all);
use base 'Debconf::DbDriver::Directory';


sub init {
	my $this=shift;
	if (! defined $this-&gt;{extension} or ! length $this-&gt;{extension}) {
		$this-&gt;{extension}=".dat";
	}
	$this-&gt;SUPER::init(@_);
}


sub save {
	my $this=shift;
	my $item=shift;

	return unless $this-&gt;accept($item);
	return if $this-&gt;{readonly};
	
	my @dirs=split(m:/:, $this-&gt;filename($item));
	pop @dirs; # the base filename
	my $base=$this-&gt;{directory};
	foreach (@dirs) {
		$base.="/$_";
		next if -d $base;
		mkdir $base or $this-&gt;error("mkdir $base: $!");
	}
	
	$this-&gt;SUPER::save($item, @_);
}


sub filename {
	my $this=shift;
	my $item=shift;
	$item =~ s/\.\.//g;
	return $item.$this-&gt;{extension};
}


sub iterator {
	my $this=shift;
	
	my @stack=();
	my $currentdir="";
	my $handle;
	opendir($handle, $this-&gt;{directory}) or
		$this-&gt;error("opendir: $this-&gt;{directory}: $!");
		
	my $iterator=Debconf::Iterator-&gt;new(callback =&gt; sub {
		my $i;
		while ($handle or @stack) {
			while (@stack and not $handle) {
				$currentdir=pop @stack;
				opendir($handle, "$this-&gt;{directory}/$currentdir") or
					$this-&gt;error("opendir: $this-&gt;{directory}/$currentdir: $!");
			}
			$i=readdir($handle);
			if (not defined $i) {
			closedir $handle;
				$handle=undef;
				next;
			}
			next if $i eq '.lock' || $i =~ /-old$/;
			if (-d "$this-&gt;{directory}/$currentdir$i") {
				if ($i ne '..' and $i ne '.') {
					push @stack, "$currentdir$i/";
				}
				next;
			}
			next unless $i=~s/$this-&gt;{extension}$//;
			return $currentdir.$i;
		}
		return undef;
	});

	$this-&gt;SUPER::iterator($iterator);
}


sub remove {
	my $this=shift;
	my $item=shift;

	my $ret=$this-&gt;SUPER::remove($item);
	return $ret unless $ret;

	my $dir=$this-&gt;filename($item);
	while ($dir=~s:(.*)/[^/]*:$1: and length $dir) {
		rmdir "$this-&gt;{directory}/$dir" or last; # not empty, I presume
	}
	return $ret;
}


1
</pre></body></html>