mkdir handler modif

Simon Perreault nomis80 at videotron.ca
Sat May 5 11:05:49 PDT 2001


As you requested, here is the modified mkdir handler.

ALFS hackers: wanna commit? Added lines 40-43.

-- 
Simon Perreault -- Public key: http://nomis80.linuxfromscratch.org/nomis80.gpg
-------------- next part --------------
<register_tag tagname="mkdir">
{
	my ($self, $elt) = @_;

	return if $elt->att('preload') eq 'yes';

	my $dir = $elt->att('dir') || "/";
	my $permissions = $elt->att('permissions') || "";
	my @dirs = split(/\s+/, $self->fix_text($elt->text));

	print "Making directories in $dir (perm: ";
	print $permissions || "default"; 
	print "):\n";
	print join (", ", @dirs) ."\n";

	return unless $self->to_continue($elt);

	while (! chdir $dir) {
		my $err_msg = {
			type => "error",
			text => "Unable to change directory to $dir",
			reason => "$!",
			input => "retry continue shell abort"
		};

		my $msg = $self->send_message($err_msg);
		$_ = $msg->{'input'};

		if    (/^retry$/i)      { next; }
		elsif (/^continue$/i)   { return; }
		elsif (/^abort$/i)      { exit 1; }
	}

	# Start creating directories.
	foreach my $d (@dirs) {
		print "\tMaking: $d\n";

		next unless $self->to_continue($elt);

		if (-e $d) {
			print "$d exists, skipping\n";
			next;
		}
		
		my $ret;
		while (! ($ret = mkdir $d, 0777)) {
			my $err_msg = {	
				type => "error",
				text => "Unable to create directory $d",
				reason => "$!",
				input => "retry continue shell abort"
			};

			my $msg = $self->send_message($err_msg);
			$_ = $msg->{'input'};

			if    (/^retry$/i)      { next; }
			elsif (/^continue$/i)   { last; }
			elsif (/^abort$/i)      { exit 1; }
		}
		next unless $ret;

		next unless $permissions;

		# mkdir() has a nice argument for this.
		while (! chmod oct($permissions), $d) {
			my $err_msg = {	
				type => "error",
				text => "Unable to set permissions for $d to $permissions",
				reason => "$!",
				input => "retry continue shell abort"
			};

			my $msg = $self->send_message($err_msg);
			$_ = $msg->{'input'};

			if    (/^retry$/i)      { next; }
			elsif (/^continue$/i)   { last; }
			elsif (/^abort$/i)      { exit 1; }
		}
	}
}
</register_tag>


More information about the alfs-discuss mailing list