#!/usr/bin/perl
# Called by new, runs as child and does various perm fixups
# on newly created object. May be safely run stackless.
#use Mooix::Thing;
run sub ($) {
	my $this=shift;

	# While the directory is still world readable, and while we can
	# still do this, fix up the .mooix file, overwriting it with one
	# owned by the right user (rename is not proxied into mood
	# currently, so the rename runs as the sandbox user, but the open
	# is done by mood, so the new file will have the right owner.
	open(OUT, ">", ".mooix.new") or $this->croak("write .mooix.new");
	close OUT;
	rename(".mooix.new", ".mooix") or $this->croak("rename .mooix.new");
	
	# Now close up the directory perms.
	chmod(0755, ".") or $this->croak("chmod");

	# Fix up the parent link while I'm at it.
	my $parent=readlink("parent");
	unlink("parent");
	symlink($parent, "parent");

	# And the owner link.
	my $owner=readlink("owner");
	if ($owner) {
		unlink("owner");
		symlink($owner, "owner");
	}
}
