bac94e2004-06-05Marc Dirix // This is a ChiliMoon module. Copyright © 2000 - 2001, Roxen IS.
d69ba52001-09-03Martin Nilsson 
a0cd4d2000-09-13Per Hedbor inherit "module";
bac94e2004-06-05Marc Dirix constant cvs_version = "$Id: tarfs.pike,v 1.13 2004/06/05 15:19:44 _cvs_dirix Exp $";
a0cd4d2000-09-13Per Hedbor  // The Filesystem.Tar module is not threadsafe.
0098ca2002-06-14Martin Nilsson constant thread_safe = 0;
a0cd4d2000-09-13Per Hedbor  #include <module.h> constant module_type = MODULE_LOCATION;
0098ca2002-06-14Martin Nilsson constant module_name = "File systems: Tar File"; constant module_doc = ("This is a file system module that makes it possible to mount a "
a0cd4d2000-09-13Per Hedbor  "directory structure from a tar-file directly on the site. gzip compressed " "tar-files are not supported"); constant module_unique = 0; void create() {
f0d6942001-01-29Per Hedbor  defvar( "mountpoint", "/",
0098ca2002-06-14Martin Nilsson  "Mount point", TYPE_LOCATION|VAR_INITIAL, "Where the module will be mounted in the site's virtual file system." );
a0cd4d2000-09-13Per Hedbor 
17013c2001-05-16Per Hedbor  defvar("tarfile", "docs.tar",
0098ca2002-06-14Martin Nilsson  "Tar file and root path", TYPE_FILE|VAR_INITIAL, "The tarfile, and an optional root path (syntax: /tar/file.tar:/root/dir/)" );
a0cd4d2000-09-13Per Hedbor }
2c17cd2001-09-25Martin Nilsson string mp;
9739932000-09-14Per Hedbor 
9ceb8b2000-09-25Per Hedbor Filesystem.Tar tar;
a0cd4d2000-09-13Per Hedbor 
17013c2001-05-16Per Hedbor string query_name() { return query("mountpoint")+" from "+query("tarfile"); }
a0cd4d2000-09-13Per Hedbor void start() { string path = "", tf = query( "tarfile" ); mp = query("mountpoint"); sscanf( tf, "%s:%s", tf, path ); tar = 0; if( catch(tar = Filesystem.Tar( tf )) ) {
2c17cd2001-09-25Martin Nilsson  report_error( "Failed to open tar-file "+tf+"!\n" );
a0cd4d2000-09-13Per Hedbor  tar = 0; }
f487162004-06-04Stephen R. van den Berg  else if( sizeof( path ) )
a0cd4d2000-09-13Per Hedbor  tar->cd( path ); } string query_location() { return mp; }
f0d6942001-01-29Per Hedbor Stat stat_file( string f, RequestID id )
a0cd4d2000-09-13Per Hedbor { if(!tar) return 0; object s = tar->stat( f ); if( s ) return ({ s->mode, s->size, s->atime, s->mtime, s->ctime, s->uid, s->gid }); } string real_file( string f, RequestID id ) { return 0; } array find_dir( string f, RequestID id ) { if(!tar) return 0; return tar->get_dir( f ); } mixed find_file( string f, RequestID id ) { if(!tar) return 0; object s = tar->stat( f ); if( !s ) return 0; if( s->isdir() ) return -1;
d99bbe2001-08-23Henrik Grubbström (Grubba)  return StringFile( tar->open( f, "r" )->read(), stat_file( f, id ));
a0cd4d2000-09-13Per Hedbor }