Beispiel #1
0
func initFileSystems() (fss []fsi.FileSystem, c aetest.Context) {

	var err error
	c, err = aetest.NewContext(nil)
	if err != nil {
		log.Fatal(err)
	}

	// defer c.Close()
	// Not here, but instead at the start of the test-funcs

	// We cant make variadic options generic,
	// since they need the concrete filesystem type.
	fs1 := dsfs.New(
		dsfs.MountName(dsfs.MountPointLast()),
		dsfs.AeContext(c),
	)

	fs3 := osfs.New()

	fs4 := memfs.New(
		memfs.Ident("m"),
	)

	fss = []fsi.FileSystem{fs1, fs3, fs4}

	return fss, c
}
Beispiel #2
0
func TestPathCleanage(t *testing.T) {

	log.SetFlags(0)

	_, c := initFileSystems()
	defer c.Close()

	cases := [][]string{
		[]string{"", "mntX/", ""},
		[]string{"/", "mntX/", ""},
		[]string{".", "mntX/", ""},
		[]string{"./", "mntX/", ""},
		[]string{"mntX", "mntX/", ""},
		[]string{"mntX/", "mntX/", ""},
		// 5...
		[]string{"file", "mntX/", "file"},
		[]string{"dir/", "mntX/", "dir/"},
		[]string{"./dir1/", "mntX/", "dir1/"},
		[]string{"mntX/dir1", "mntX/", "dir1"},
		[]string{"mntX/dir1/file2", "mntX/dir1/", "file2"},
		// 10
		[]string{"mntY/dir1/file2", "mntX/mntY/dir1/", "file2"},
		[]string{"///mntX/dir1/dir2///dir3/", "mntX/dir1/dir2/", "dir3/"},
		[]string{"mntX/dir1/dir2///file3", "mntX/dir1/dir2/", "file3"},
		[]string{"/dir1/dir2///file3", "mntX/dir1/dir2/", "file3"},
		[]string{"dir1/dir2///dir3/", "mntX/dir1/dir2/", "dir3/"},
		// 15
		[]string{"c:\\dir1\\dir2", "mntX/c:/dir1/", "dir2"},
	}

	fs := memfs.New(
		memfs.Ident("mntX"),
	)
	for i, v := range cases {
		inpt := v[0]
		_ = inpt
		wnt1 := v[1]
		wnt2 := v[2]
		dir, bname := common.UnixPather(v[0], fs.RootDir())
		fullpath := dir + bname

		log.Printf("#%2v %-30q %-24q => %-16q %-12q ", i, inpt, dir, bname, fullpath)

		if wnt1 != dir {
			t.Errorf("dir   #%2v got %-24v - wnt %-16v\n", i, dir, wnt1)
		}
		if wnt2 != bname {
			t.Errorf("bname #%2v got %-24v - wnt %-16v\n", i, bname, wnt2)
		}
		if wnt1+wnt2 != fullpath {
			t.Errorf("fullp #%2v got %-24v - wnt %-16v\n", i, fullpath, wnt1+wnt2)
		}
	}

}
Beispiel #3
0
func deleteAll(w http.ResponseWriter, r *http.Request, m map[string]interface{}) {

	lg, _ := loghttp.BuffLoggerUniversal(w, r)

	err := r.ParseForm()
	lg(err)

	wpf(w, tplx.ExecTplHelper(tplx.Head, map[string]interface{}{"HtmlTitle": "Delete all filesystem data"}))
	defer wpf(w, tplx.Foot)

	confirm := r.FormValue("confirm")
	if confirm != "yes" {
		wpf(w, "All dsfs contents are deletes. All memfs contents are deleted<br>\n")
		wpf(w, "Put a get param into the URL ?confirm - and set it to 'yes'<br>\n")
		wpf(w, "Put a get param 'mountname' into url; i.e. mountname=mntftch<br>\n")
		return
	}

	wpf(w, "<pre>\n")
	defer wpf(w, "\n</pre>")

	//
	//
	fs := dsfs.New(
		dsfs.AeContext(appengine.NewContext(r)),
	)

	mountName := r.FormValue("mountname")
	if mountName != "" {
		wpf(w, "mountame = "+mountName+"\n")
		fs = dsfs.New(
			dsfs.AeContext(appengine.NewContext(r)),
			dsfs.MountName(mountName),
		)
	}

	wpf(w, "dsfs:\n")
	msg, err := fs.DeleteAll()
	if err != nil {
		wpf(w, "err during delete %v\n", err)
	}
	wpf(w, msg)

	memMapFileSys = memfs.New()
	wpf(w, "\n")
	wpf(w, "memMapFs new")

	// cleanup must be manual
	osFileSys = osfs.New()

}
Beispiel #4
0
	"bytes"
	"os"

	"github.com/pbberlin/tools/net/http/loghttp"
	"github.com/pbberlin/tools/os/fsi"
	"github.com/pbberlin/tools/os/fsi/common"
	"github.com/pbberlin/tools/os/fsi/dsfs"
	"github.com/pbberlin/tools/os/fsi/memfs"
	"github.com/pbberlin/tools/os/fsi/osfs"
	"golang.org/x/net/context"
	"golang.org/x/net/html"
)

var logDir = "c:/tmp/dedup/"

var memMapFileSys = memfs.New(memfs.DirSort("byDateDesc")) // package variable required as "persistence"

func GetFS(c context.Context, whichType int) (fs fsi.FileSystem) {

	switch whichType {
	case 0:
		// re-instantiation would delete contents
		fs = fsi.FileSystem(memMapFileSys)
	case 1:
		// must be re-instantiated for each request
		dsFileSys := dsfs.New(dsfs.DirSort("byDateDesc"), dsfs.MountName("mntTest"), dsfs.AeContext(c))
		fs = fsi.FileSystem(dsFileSys)
	case 2:

		osFileSys := osfs.New(osfs.DirSort("byDateDesc"))
		fs = fsi.FileSystem(osFileSys)
Beispiel #5
0
import (
	"bytes"
	"net/http"
	"strconv"

	"github.com/pbberlin/tools/net/http/tplx"
	"github.com/pbberlin/tools/os/fsi"
	"github.com/pbberlin/tools/os/fsi/dsfs"
	"github.com/pbberlin/tools/os/fsi/memfs"
	"github.com/pbberlin/tools/os/fsi/osfs"
	"github.com/pbberlin/tools/os/fsi/tests"
	"golang.org/x/net/context"
	"google.golang.org/appengine"
)

var memMapFileSys = memfs.New()
var osFileSys = osfs.New()

// var dsFileSys = // cannot be instantiated without ae.context

var whichType = 0

func setFSType(w http.ResponseWriter, r *http.Request, m map[string]interface{}) {

	wpf(w, tplx.ExecTplHelper(tplx.Head, map[string]interface{}{"HtmlTitle": "Set filesystem type"}))
	defer wpf(w, tplx.Foot)

	stp := r.FormValue("type")
	newTp, err := strconv.Atoi(stp)

	if err == nil && newTp >= 0 && newTp <= 2 {
Beispiel #6
0
import (
	"bytes"
	"net/http"
	"sync"

	"github.com/pbberlin/tools/net/http/loghttp"
	"github.com/pbberlin/tools/os/fsi/dsfs"
	"github.com/pbberlin/tools/os/fsi/memfs"
	"google.golang.org/appengine"
)

const TplPrefix = "/mnt02"
const pathToTmpl = "/page/programmatic_content/index.html"

var fs1 = memfs.New(
	memfs.Ident(TplPrefix[1:]), // a closured variable in init( ) did not survive map-pointer reallocation
)

// Implements fsi.File
type SyncedMap struct {
	sync.Mutex
	mp map[string]string
}

// We need this, since we have that additional step of putting the {{ .Variable }} strings into the hugo html
var mp = SyncedMap{mp: map[string]string{}}

func TemplateFromHugoReset(w http.ResponseWriter, r *http.Request, mapOnerous map[string]interface{}) {
	r.Header.Set("X-Custom-Header-Counter", "nocounter")

	mpOld := mp