added disk quota

This commit is contained in:
ston1th 2022-03-17 00:47:45 +01:00
commit 9cc2b04342
26 changed files with 1376 additions and 61 deletions

View file

@ -7,7 +7,9 @@ import (
"io"
stdfs "io/fs"
"net/http"
"os"
"path"
"runtime"
"strings"
"cachefs/pkg/fs"
@ -15,6 +17,21 @@ import (
"github.com/go-logr/logr"
)
func PrintStack() {
os.Stderr.Write(Stack())
}
func Stack() []byte {
buf := make([]byte, 1024)
for {
n := runtime.Stack(buf, true)
if n < len(buf) {
return buf[:n]
}
buf = make([]byte, 2*len(buf))
}
}
type FileServer struct {
log logr.Logger
fs *fs.FS
@ -51,13 +68,17 @@ func (fs *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
r.URL.Path = upath
}
p := path.Clean(upath)
option := r.FormValue("o")
if option == "debug" {
PrintStack()
}
d, _, err := fs.fs.StatWithOffline(p)
if err != nil {
msg, code := toHTTPError(err)
http.Error(w, msg, code)
return
}
option := r.FormValue("o")
//option := r.FormValue("o")
if option == "v" {
err = video.Execute(w, r.URL.Path)
if err != nil {