Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Additional files added to the plug-in

Quote Reply
Additional files added to the plug-in
Alex,

When files are added to the .tar, is there a way to make sure the files are set to run as 755? Also the option to add templates would be nice too.

This can be done editing the install.pm file, but it would seem it should be be possible to have a different function to install into the cgi- directories, than into the template ones. cgi_copy would make sure file permissions were set to execute, and file_copy would make sure that it was set to server-read/write.



PUGDOGŪ Enterprises, Inc.
FAQ:http://LinkSQL.com/FAQ
Forum:http://LinkSQL.com/forum
Quote Reply
Re: Additional files added to the plug-in In reply to
Hi,

This can be done with the tar module quite easily, and I opted for this instead of an API because of the vast number of options I was running into. Basically to add a .cgi file you do:

my $file = $tar->get_file ('newfile.cgi');
$file->mode (0755);
$file->name ("$CFG->{admin_root_path}/newfile.cgi");
unless ($file->write) {
$Plugins::Yourplugin::error = "Unable to extract newfile.cgi. Reason: $GT::Tar::error";
return;
}

You can similarily extract templates or other files and set permissions as above. The one gotcha is to not use quotes when setting the mode. If you do $file->mode('0755') it will not be what you want.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Additional files added to the plug-in In reply to
I have a piece of code I munged from a bunch of code samples.

But you also need to change the path-to-perl to the users default,
and the admin library to the users admin.

It's fine for the regex to change the first line of the file, for
perl, that never changes.

But 'use lib' line, is a problem. There might be more than one
use lib in a file, so there should be a standard replace, such as

use lib 'links/admin'

which would be an exact pattern match for replacing the lib line.

These should be functions as well, so that:

Code:
my $file = $tar->get_file ('newfile.cgi');
$file->mode (0755);
$file->name ("$CFG->{admin_root_path}/newfile.cgi");
$file->path_to_perl (); ## where () can take an optional arguement
$file->path_to_admin_lib (); ## where () can take an optional arguement
unless ($file->write) {
$Plugins::Yourplugin::error = "Unable to extract newfile.cgi. Reason: $GT::Tar::error";
return;
}
The code I'm using I cut from a few scripts, and tweaked to make them work <G>

Code:
# Copying recommend.it.cgi to user_cgi directory.
$file = $tar->get_file ('recommend.it.cgi');
# Get the entire code as a string.
my $code = $file->body_as_string;
# Replace the path to perl with the users perl.
$code =~ s/^#!(.*)/#!$CFG->{path_to_perl}/;
# Replace the use lib with the users admin directory.
$code =~ s/use lib '[^']+'/use lib '$CFG->{admin_root_path}'/;
$file->body ($code);
# Set the name of the file
$file->name ("$CFG->{admin_root_path}/../recommend.it.cgi");
So, it would be much, much nicer to have the routines all in $file->,
so that they can be changed in one place, not in every plug-in.



PUGDOGŪ Enterprises, Inc.
FAQ:http://LinkSQL.com/FAQ
Forum:http://LinkSQL.com/forum