# SPDX-License-Identifier: curl
#
###########################################################################
-%file_chmod1 = (
+
+package directories;
+
+use strict;
+use warnings;
+
+BEGIN {
+ use base qw(Exporter);
+
+ our @EXPORT = qw(
+ ftp_contentlist
+ wildcard_filesize
+ wildcard_getfile
+ );
+}
+
+
+my %file_chmod1 = (
'name' => 'chmod1',
'content' => "This file should have permissions 444\n",
'perm' => 'r--r--r--',
'dostime' => '01-11-10 10:00AM',
);
-%file_chmod2 = (
+my %file_chmod2 = (
'name' => 'chmod2',
'content' => "This file should have permissions 666\n",
'perm' => 'rw-rw-rw-',
'dostime' => '02-01-10 08:00AM',
);
-%file_chmod3 = (
+my %file_chmod3 = (
'name' => 'chmod3',
'content' => "This file should have permissions 777\n",
'perm' => 'rwxrwxrwx',
'dostime' => '02-01-10 08:00AM',
);
-%file_chmod4 = (
+my %file_chmod4 = (
'type' => 'd',
'name' => 'chmod4',
'content' => "This file should have permissions 001\n",
'dostime' => '05-04-10 04:31AM'
);
-%file_chmod5 = (
+my %file_chmod5 = (
'type' => 'd',
'name' => 'chmod5',
'content' => "This file should have permissions 110\n",
'dostime' => '05-04-10 04:31AM'
);
-%link_link = (
+my %link_link = (
'type' => 'l',
'name' => 'link -> file.txt',
'size' => '8',
'time' => 'Jan 6 4:42'
);
-%link_link_absolute = (
+my %link_link_absolute = (
'type' => 'l',
'name' => 'link_absolute -> /data/ftp/file.txt',
'size' => '15',
'time' => 'Jan 6 4:45'
);
-%dir_dot = (
+my %dir_dot = (
'type' => "d",
'name' => ".",
'hlink' => "4",
'perm' => "rwxrwxrwx"
);
-%dir_ddot = (
+my %dir_ddot = (
'type' => "d",
'name' => "..",
'hlink' => "4",
'perm' => "rwxrwxrwx"
);
-%dir_weirddir_txt = (
+my %dir_weirddir_txt = (
'type' => "d",
'name' => "weirddir.txt",
'hlink' => "2",
'perm' => "rwxr-xrwx"
);
-%dir_UNIX = (
+my %dir_UNIX = (
'type' => "d",
'name' => "UNIX",
'hlink' => "11",
'perm' => "rwx--x--x"
);
-%dir_DOS = (
+my %dir_DOS = (
'type' => "d",
'name' => "DOS",
'hlink' => "11",
'perm' => "rwx--x--x"
);
-%dir_dot_NeXT = (
+my %dir_dot_NeXT = (
'type' => "d",
'name' => ".NeXT",
'hlink' => "4",
'perm' => "rwxrwxrwx"
);
-%file_empty_file_dat = (
+my %file_empty_file_dat = (
'name' => "empty_file.dat",
'content' => "",
'perm' => "rw-r--r--",
'dostime' => "04-27-10 11:01AM"
);
-%file_file_txt = (
+my %file_file_txt = (
'name' => "file.txt",
'content' => "This is content of file \"file.txt\"\n",
'time' => "Apr 27 11:01",
'perm' => "rw-r--r--"
);
-%file_someothertext_txt = (
+my %file_someothertext_txt = (
'name' => "someothertext.txt",
'content' => "Some junk ;-) This file does not really exist.\n",
'time' => "Apr 27 11:01",
'perm' => "rw-r--r--"
);
-%lists = (
+my %lists = (
'/fully_simulated/' => {
'files' => [ \%dir_dot, \%dir_ddot, \%dir_DOS, \%dir_UNIX ],
'eol' => "\r\n",
}
);
-sub ftp_createcontent($) {
- my (%list) = @_;
+sub ftp_createcontent {
+ my ($list) = $_[0];
- $type = $$list{'type'};
- $eol = $$list{'eol'};
- $list_ref = $$list{'files'};
+ my $type = $$list{'type'};
+ my $eol = $$list{'eol'};
+ my $list_ref = $$list{'files'};
my @diroutput;
my @contentlist;
my $fuser = $file{'user'} ? sprintf("%15s", $file{'user'}) : "ftp-default";
my $fgroup = $file{'group'} ? sprintf("%15s", $file{'group'}) : "ftp-default";
my $fsize = "";
- if($file{'type'} eq "d") {
+ if(exists($file{'type'}) && $file{'type'} eq "d") {
$fsize = $file{'size'} ? sprintf("%7s", $file{'size'}) : sprintf("%7d", 4096);
}
else {
- $fsize = sprintf("%7d", length $file{'content'});
+ $fsize = sprintf("%7d", exists($file{'content'}) ? length $file{'content'} : 0);
}
my $fhlink = $file{'hlink'} ? sprintf("%4d", $file{'hlink'}) : " 1";
my $ftime = $file{'time'} ? sprintf("%10s", $file{'time'}) : "Jan 9 1933";
my $line = "";
my $time = $file{'dostime'} ? $file{'dostime'} : "06-25-97 09:12AM";
my $size_or_dir;
- if($file{'type'} =~ /^d$/) {
+ if(exists($file{'type'}) && $file{'type'} =~ /^d$/) {
$size_or_dir = " <DIR> ";
}
else {
}
}
-sub wildcard_filesize($$) {
+sub wildcard_filesize {
my ($list_type, $file) = @_;
- $list = $lists{$list_type};
+ my $list = $lists{$list_type};
if($list) {
my $files = $list->{'files'};
for(@$files) {
}
return -1;
}
-sub wildcard_getfile($$) {
+
+sub wildcard_getfile {
my ($list_type, $file) = @_;
- $list = $lists{$list_type};
+ my $list = $lists{$list_type};
if($list) {
my $files = $list->{'files'};
for(@$files) {
if($f{'content'}) {
return (length $f{'content'}, $f{'content'});
}
- elsif ($f{'type'} ne "d"){
+ elsif (!exists($f{'type'}) or $f{'type'} ne "d"){
return (0, "");
}
else {
sub ftp_contentlist {
my $listname = $_[0];
- $list = $lists{$listname};
- return ftp_createcontent(\$list);
+ my $list = $lists{$listname};
+ return ftp_createcontent($list);
}