From: Rob H. <for...@us...> - 2001-11-15 19:46:23
|
Update of /cvsroot/sandweb/sandweb/lib/SandWeb In directory usw-pr-cvs1:/tmp/cvs-serv4353/lib/SandWeb Modified Files: File.pm Log Message: hooked up File object, using file subroutine in sandweb.cgi This implementation is still somewhat raw; $file->get_user() and get_group() return uid/gid instead of full filename. Pretty cool besides that. Index: File.pm =================================================================== RCS file: /cvsroot/sandweb/sandweb/lib/SandWeb/File.pm,v retrieving revision 1.7 retrieving revision 1.8 diff -U2 -r1.7 -r1.8 --- File.pm 2001/10/10 07:27:01 1.7 +++ File.pm 2001/11/15 19:46:20 1.8 @@ -10,10 +10,6 @@ my $self = bless { - 'owner' => $args{'owner'}, - 'group' => $args{'group'}, 'filename' => $args{'filename'}, 'location' => $args{'location'}, - 'permissions' => $args{'permissions'}, - 'file_type' => $args{'file_type'}, }, $class; @@ -23,10 +19,23 @@ sub get_owner { my $self = shift; - return $self->{'owner'}; + my $location = $self->{'location'}; + my $filename = $self->{'filename'}; + + ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, + $atime,$mtime,$ctime,$blksize,$blocks) + = stat("$location/$filename"); + + my $owner = $uid; + return $owner; } sub get_group { my $self = shift; - return $self->{'group'}; + ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, + $atime,$mtime,$ctime,$blksize,$blocks) + = stat("$location/$filename"); + + my $group = $gid; + return $group; } @@ -36,12 +45,37 @@ } +sub get_location { + my $self = shift; + return $self->{'filename'}; +} + sub get_permissions { my $self = shift; - return $self->{'permissions'}; + ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, + $atime,$mtime,$ctime,$blksize,$blocks) + = stat("$location/$filename"); + + return $mode & 0777; } sub get_file_type { my $self = shift; - return $self->{'file_type'}; + + my $location = $self->{'location'}; + my $filename = $self->{'filename'}; + + if (-d "$location/$filename") { + $file_type = 'Directory'; + } + elsif (-T "$location/$filename") { + $file_type = 'Text'; + } + elsif (-B "$location/$filename") { + $file_type = 'Binary'; + } else { + $file_type = 'Unknown'; + } + + return $file_type; } |