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 }
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() }
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) os.Chdir(logDir) default: panic("invalid whichType ") } return }
// GetFS instantiates a filesystem, depending on whichtype func GetFS(c context.Context) (fs fsi.FileSystem) { switch whichType { case 0: // must be re-instantiated for each request docRoot = "" dsFileSys := dsfs.New(dsfs.DirSort("byDateDesc"), dsfs.MountName(mountName), dsfs.AeContext(c)) fs = fsi.FileSystem(dsFileSys) case 1: docRoot = "c:/docroot/" os.Chdir(docRoot) osFileSys := osfs.New(osfs.DirSort("byDateDesc")) fs = fsi.FileSystem(osFileSys) case 2: // re-instantiation would delete contents docRoot = "" fs = fsi.FileSystem(memMapFileSys) default: panic("invalid whichType ") } return }
"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 { whichType = newTp