[Xitami] chmodd's for cgi - help please

Francis Turner xitami@lists.xitami.org
Tue, 23 Oct 2001 18:35:41 +0200


Ashfield Web Services Ltd wrote:

>Thanks for reply.
>
>That is how I understood it but I have got a situation that when running a
>cgi script I get the error "can't write to fileX.etc ....check permissions"
>
Ummm.

If you are running a perl CGI script and the perl CGI script in question 
is trying to read or modify a file in a non-existent directory then it 
may be returning an error that is then mangled like this.

For example if you do an
  open <FILE> ">/usr/tmp/tmpfile" somewhere in your script but you have 
no /usr/tmp directory - which is rarely the case in windows - then you 
will get an error about the inability to open a file which may then try 
and helpfully suggest you need permissions changed when actually what 
you need to do is either create the directories /usr and /usr/tmp/ or 
(better) change the path to something suitable such as /windows/TEMP/. 
By the way it is worth noting that activestate perl is pretty relaxed 
about / and \ as is Xitami so its better to use / unless you really have 
to speciff C:\windows\temp\filename because zou have to pass this to a 
command shell.

Francis

PS the below perl function is one I use to create paths for files that 
may not have one. remove the print statements if you don't want to be 
warned that this is happening

# utility function to create directory tree if it doesn't exist.
# example usage:  pavePath('/results/http/site/dir/subdir/file.htm')
#   will create as many of
# /results/,
# /results/http/,
# /results/http/site/,
# /results/http/site/dir/
# and /results/http/site/dir/subdir/ as required
# arguably it may be more efficient to start from the full path and work 
backwards?
sub pavePath {
    my ($fQname) = @_;
    return if (-d(substr ($fQname,0,rindex($fQname,'/')))); # if path 
exists quit now
    my ($ch) = index($fQname,'/',1); # avoid trying to create the / 
directory!
    print 'paving...';
    while($ch>=0) {
        mkdir(substr($fQname,0,$ch)) unless -d(substr($fQname,0,$ch));
        print substr ($fQname,0,$ch),":\n";
        $ch=index($fQname,'/',$ch+1);
    }
}