1
  
2
  
3
  
4
  
5
  
6
  
7
  
8
  
9
  
10
  
11
  
12
  
13
  
14
  
15
  
16
  
17
  
18
  
19
  
20
  
21
  
22
  
23
  
24
  
25
  
26
  
27
  
28
  
29
  
30
  
31
  
32
  
33
  
34
  
35
  
36
  
37
  
38
  
39
  
40
  
41
  
42
  
43
  
44
  
45
  
46
  
47
  
48
  
49
  
50
  
51
  
52
  
53
  
54
  
55
  
56
  
57
  
58
  
59
  
60
  
61
  
62
  
63
  
64
  
65
  
66
  
67
  
68
  
69
  
70
  
71
  
72
  
73
  
74
  
75
  
76
  
77
  
78
  
79
  
80
  
81
  
82
  
83
  
84
  
85
  
86
  
87
  
88
  
inherit "module"; 
 
constant cvs_version= "$Id: tarfs.pike,v 1.5 2001/01/29 05:40:30 per Exp $"; 
 
// The Filesystem.Tar module is not threadsafe. 
constant thread_safe=0; 
 
//<locale-token project="mod_targs">_</locale-token> 
#define _(X,Y)        _DEF_LOCALE("mod_tarfs",X,Y) 
// end of the locale related stuff 
#include <module.h> 
 
constant module_type = MODULE_LOCATION; 
LocaleString module_name = _(0,"Tarfile system"); 
LocaleString module_doc = 
_(0,"This is a file system module that makes it possible to mount a " 
 "directory structure from a tar-file directly on the site. gzip compressed " 
 "tar-files are not supported"); 
constant module_unique = 0; 
 
void create() 
{ 
  defvar( "mountpoint", "/",  
          _(0,"Mount point"), TYPE_LOCATION|VAR_INITIAL, 
          _(0,"Where the module will be mounted in the site's virtual file " 
          "system.") ); 
 
  defvar("tarfile", "config_interface/docs.tar",  
         _(0,"Tar file and root path"), TYPE_FILE|VAR_INITIAL, 
         _(0,"The tarfile, and an optional root path (syntax: /tar/file.tar:/" 
           "root/dir/)") ); 
} 
 
string mp, error_msg; 
 
Filesystem.Tar tar; 
 
void start() 
{ 
  string path = "", tf = query( "tarfile" ); 
  mp = query("mountpoint"); 
  sscanf( tf, "%s:%s", tf, path ); 
  tar = 0; 
  if( catch(tar = Filesystem.Tar( tf )) ) 
  { 
    report_error( "Failed to open tar-file "+tf+"!" ); 
    tar = 0; 
  } 
  else if( strlen( path ) ) 
    tar->cd( path ); 
} 
 
 
string query_location() 
{ 
  return mp; 
} 
 
Stat stat_file( string f, RequestID id ) 
{ 
  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; 
  return id->conf->StringFile( tar->open( f, "r" )->read(),  
                               stat_file( f, id )); 
}