App-Manager
view release on metacpan or search on metacpan
sub xlstat($) {
my @stat = lstat $_[0];
@stat ?
{
path => $_[0],
dev => $stat[ 0],
ino => $stat[ 1],
mode => $stat[ 2],
nlink => $stat[ 3],
uid => $stat[ 4],
gid => $stat[ 5],
rdev => $stat[ 6],
size => $stat[ 7],
atime => $stat[ 8],
mtime => $stat[ 9],
ctime => $stat[10],
blksize => $stat[11],
blocks => $stat[12],
}
:
{
$stat->{savetype} = 0;
}
} elsif (S_ISDIR $stat->{mode}) {
$samecontent = 1;
} elsif (S_ISLNK $stat->{mode}) {
$samecontent = $stat->{symlink} eq readlink $stat->{path};
}
$msg = "attributes changed" if $samecontent;
if ($samecontent
&& $stat->{uid} eq $nstat->{uid}
&& $stat->{gid} eq $nstat->{gid}
&& $stat->{size} eq $nstat->{size}
&& ($level > 0 || $stat->{mtime} eq $nstat->{mtime})) {
$msg = "no change";
delete $self->{storage}{$stat->{id}};
delete $self->{source}{$stat->{path}};
}
}
slog 3,"$stat->{path}: $msg";
$stat->{ctype} = $msg;
} else {
} elsif (S_ISDIR $stat->{mode}) {
remove $stat->{path};
mkdir $stat->{path},$stat->{mode} & 07777
or die "Unable to recreate directory '$stat->{path}': $!\n";
} else {
die "FATAL: don't know how to check in $stat->{path}.\n";
}
unless (S_ISLNK $stat->{mode}) {
chmod $stat->{mode} & 07777,$stat->{path}
or die "Unable to change mode for '$stat->{path}': $!\n";
chown $stat->{uid},$stat->{gid},$stat->{path}
or warn "Unable to change user and group id for '$stat->{path}': $!\n";
utime $stat->{atime},$stat->{mtime},$stat->{path}
or warn "Unable to change atime and mtime for '$stat->{path}': $!\n";
}
}
}
# this is safe as long as we don't sync too early
sub swap {
my $self=shift;
strftime "%Y-%m-%d %H:%M:%S",localtime shift;
}
sub cmd_info {
die "no database specified\n" unless @ARGV; my $db = App::Manager::DB->open(shift @ARGV);
print "database path: $db->{path}\n";
print "creation time: ".(ltime $db->{ctime})."\n";
print "modification time: ".(ltime $db->{mtime})."\n";
while (my ($id,$stat) = each %{$db->storage}) {
printf "%5s %5s %9s %s %s\n",$stat->{uid},$stat->{gid},$stat->{size},ltime $stat->{mtime},$stat->{path};
}
}
sub cmd_swap {
die "no database specified\n" unless @ARGV; my $db = App::Manager::DB->open(shift @ARGV);
$db->swap;
}
die "no command specified\n" unless @ARGV; $cmd = shift;
Which prints:
APPMAN: opening db /var/appman/test
database path: /var/appman/test
creation time: 1999-06-14 14:14:05
modification time: 1999-06-14 14:14:05
1970-01-01 01:00:00 /bin/appmantest
This means that /bin/appmantest was overwritten. Since no such file
existed before, the filetime and uid/gid information is not valid.
If you want to restore the file again (in this case just delete it), all you have to do is to enter:
appman swap test
=head1 AUTHOR
Marc Lehmann <pcg@goof.com>.
( run in 0.549 second using v1.01-cache-2.11-cpan-5735350b133 )