fix dev-server for file embedding

Change-Id: I23254930eaedf11a87389d85f54f86bafac20866
This commit is contained in:
Brad Fitzpatrick 2012-02-29 08:01:59 -08:00
parent 1642f9116c
commit 7751fac185
2 changed files with 14 additions and 3 deletions

View File

@ -14,6 +14,7 @@ my $opt_wipe;
my $opt_tls;
my $opt_nobuild;
my $opt_all; # listen on all interfaces
my $opt_staticres; # use static resources, not those on disk
# keep indexes in memory only. often used with --wipe, but not
# necessarily. if --wipe isn't used, all blobs are re-indexed
@ -28,6 +29,7 @@ GetOptions("wipe" => \$opt_wipe,
"memory" => \$opt_memory,
"mongo" => \$opt_mongo,
"mysql" => \$opt_mysql,
"staticres" => \$opt_staticres,
)
or usage();
@ -125,7 +127,9 @@ $ENV{CAMLI_DBNAME} = $DBNAME;
# To use resources from disk, instead of the copies linked into the
# binary:
$ENV{CAMLI_DEV_UI_FILES} = "$FindBin::Bin/server/go/camlistored/ui"; # set in server/go/camlistored/ui/fileembed.go
unless ($opt_staticres) {
$ENV{CAMLI_DEV_UI_FILES} = "$FindBin::Bin/server/camlistored/ui"; # set in server/camlistored/ui/fileembed.go
}
exec("./gopath/bin/camlistored",
"-configfile=$Bin/config/dev-server-config.json",

View File

@ -23,6 +23,7 @@ import (
"net/http"
"os"
"path/filepath"
"strings"
"sync"
"time"
)
@ -67,9 +68,15 @@ func (f *Files) add(filename string, sf *staticFile) {
f.file[filename] = sf
}
func (f *Files) Open(filename string) (http.File, error) {
var _ http.FileSystem = (*Files)(nil)
func (f *Files) Open(filename string) (hf http.File, err error) {
if strings.HasPrefix(filename, "/") {
filename = filename[1:]
}
if e := f.OverrideEnv; e != "" && os.Getenv(e) != "" {
return os.Open(filepath.Join(os.Getenv(e), filename))
diskPath := filepath.Join(os.Getenv(e), filename)
return os.Open(diskPath)
}
f.lk.Lock()
defer f.lk.Unlock()