Преглед изворни кода

Add basedir option to the ini file

Andy Baugh пре 1 година
родитељ
комит
e06699ccdc
2 измењених фајлова са 8 додато и 1 уклоњено
  1. 6 0
      bin/tpsgi
  2. 2 1
      lib/TPSGI.pm

+ 6 - 0
bin/tpsgi

@@ -26,6 +26,7 @@ tpsgi obeys a config file, ~/.tpsgi.ini which is in Config::Simple (key=value) f
     loggers     # Logger module(s), separate with comma
     auth        # Authentication module
     domain      # Domain name of the application, used by things like service files
+    basedir     # Directory you want to base this out of (defaults to HOME).
 
 The idea is that this application is going to be run in a chroot with the user's homedir being the application dir.
 
@@ -35,11 +36,16 @@ sub main {
     my (@args) = @_;
 
     my %options = TPSGI::get_config();
+
     return %options;
 }
 
 our $app = sub {
     $options{verbose} = 1;
+
+    # Change your dir into whatever basedir you need to be in
+    chdir($options{'basedir'}) or warn "Can't chdir into $options{'basedir'}: $!";
+
     my $self = TPSGI->new(%options);
     return eval { $self->app(@_) } || do {
 		my $env = shift;

+ 2 - 1
lib/TPSGI.pm

@@ -833,6 +833,7 @@ sub static {
 }
 
 sub get_config {
+    $ENV{HOME} ||= Cwd::getcwd();
     my %options = (
         verbose    => 0,
         custom_log => undef,
@@ -842,8 +843,8 @@ sub get_config {
         domain     => '',
         user       => '',
         binds      => [],
+        basedir    => $ENV{'HOME'},
     );
-    $ENV{HOME} ||= Cwd::getcwd();
     my $config_file = "$ENV{HOME}/.tpsgi.ini";
     if (-f $config_file) {
         my $conf = Config::Simple->new($config_file);