From b77e312f5c9c192750c70ca95f9ad0aa3bdc668d Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Mon, 10 Sep 2012 21:30:24 +0200 Subject: Add determination of specific OS path type. --- src/ninjacloud.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/ninjacloud.go b/src/ninjacloud.go index 9ec2962..cb99446 100644 --- a/src/ninjacloud.go +++ b/src/ninjacloud.go @@ -9,6 +9,7 @@ import ( "net/http" "os" "path/filepath" + "runtime" ) const APP_NAME = "Ninja Go Local Cloud" @@ -160,11 +161,20 @@ func copyDir(source string, dest string) (err error) { //////// REQUEST HANDLERS +func osPath(p string) string { + filepath.Clean(p) + if runtime.GOOS == "windows" { + p = p[:1] + ":" + p[1:] + } else { + p = "/" + p + } + return p +} + //// File APIs func fileHandler(w http.ResponseWriter, r *http.Request) { - p := r.URL.Path[filePathLen:] - filepath.Clean(p) + p := osPath(r.URL.Path[filePathLen:]) if !isInRoot(p) { w.WriteHeader(http.StatusForbidden) return @@ -277,8 +287,7 @@ func fileHandler(w http.ResponseWriter, r *http.Request) { //// Directory APIs func dirHandler(w http.ResponseWriter, r *http.Request) { - p := r.URL.Path[dirPathLen:] - filepath.Clean(p) + p := osPath(r.URL.Path[dirPathLen:]) if !isInRoot(p) { w.WriteHeader(http.StatusForbidden) return -- cgit v1.2.3