Filesys-Virtual-Plain

 view release on metacpan or  search on metacpan

Plain.pm  view on Meta::CPAN

		$atime,$mtime,$ctime,$blksize,$blocks) = CORE::stat($fn);
		
	my ($sec, $min, $hr, $dd, $mm, $yy, $wd, $yd, $isdst) =
		localtime($mtime); $yy += 1900; $mm++;
		
	return (1,"$yy$mm$dd$hr$min$sec");
}

=pod

=head2 size($file)

Gets the size of a file in bytes.

=cut

sub size {
	my ($self, $fn) = @_;
	$fn = $self->_path_from_root($fn);

	return (CORE::stat($fn))[7];
}

=pod

=head2 delete($file)

Deletes a file, returns 1 or 0 on success or failure.

=cut

sub delete {
	my ($self, $fn) = @_;
	$fn = $self->_path_from_root($fn);

	return ((-e $fn) && (!-d $fn) && (unlink($fn))) ? 1 : 0;
}

=pod

=head2 chdir($dir)

Changes the cwd to a new path from root_path.
Returns undef on failure or the new path on success.

=cut

sub chdir {
	my ($self, $dir) = @_;

	my $new_cwd = $self->_resolve_path($dir);
	my $full_path = $self->root_path().$new_cwd;

	return ((-e $full_path) && (-d $full_path)) ? $self->cwd($new_cwd) : undef;
}

=pod

=head2 mkdir($dir, $mode)

Creats a directory with $mode (defaults to 0755) and chown()'s the directory
with the uid and gid.  The return value is from mkdir().

=cut

sub mkdir {
	my ($self, $dir, $mode) = @_;
	$dir = $self->_path_from_root($dir);

	return 2 if (-d $dir);
	
	$mode ||= 0755;
	
	my $ret = (mkdir($dir, $mode)) ? 1 : 0;
	
	if ($ret) {
		chown($self->{uid}, $self->{gid}, $dir);
	}
	return $ret;
}

=pod

=head2 rmdir($dir)

Deletes a directory or file if -d test fails.  Returns 1 on success or 0 on
failure.

=cut

sub rmdir {
	my ($self, $dir) = @_;
	$dir = $self->_path_from_root($dir);

	if (-e $dir) {
		if (-d $dir) {
			return 1 if (rmdir($dir));
		} else {
			return 1 if (unlink($dir));
		}
	}

	return 0;
}

=pod

=head2 list($dir)

Returns an array of the files in a directory.

=cut

sub list {
	my ($self, $dirfile) = @_;
	$dirfile = $self->_path_from_root($dirfile);
		
	my @ls;
		
	if(-e $dirfile) {
		if(!-d $dirfile) {
			### This isn't a directory, so derive its short name, and push it.
			my @parts = split(/\//, $dirfile);
			push(@ls, pop @parts);
		} else {
			### Open the directory and get a file list.
            opendir(DIR, $dirfile);
            my @files = readdir(DIR);
			closedir(DIR);
						
			### Process the files...
            @ls = (sort @files);
		}
	}
	
	return @ls;
}



( run in 0.817 second using v1.01-cache-2.11-cpan-71847e10f99 )