Skip to content

Commit a189b77

Browse files
committed
First time working
1 parent e89fb44 commit a189b77

File tree

3 files changed

+56
-5
lines changed

3 files changed

+56
-5
lines changed

davoop/filesystem.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package davoop
22

33
import (
4-
"log"
54
"os"
65
"path"
76
"path/filepath"
@@ -41,7 +40,7 @@ func (d HDFSDir) sanitizePath(name string) (string, error) {
4140
}
4241
dir = filepath.Join(dir, filepath.FromSlash(path.Clean("/"+name)))
4342

44-
log.Println(name, " -> ", dir)
43+
// log.Println(name, " -> ", dir)
4544

4645
return dir, nil
4746
}

main.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,48 @@
11
package main
22

3+
import (
4+
"log"
5+
"net/http"
6+
7+
"fmt"
8+
9+
"github.com/codeteam/davoop/davoop"
10+
"github.com/codeteam/davoop/webdav"
11+
"github.com/kelseyhightower/envconfig"
12+
)
13+
14+
type Configuration struct {
15+
NameNode string
16+
User string
17+
Path string `default:"/"`
18+
19+
Addr string `default:":8080"`
20+
21+
Listing bool `default:"true"`
22+
ReadOnly bool `default:"false"`
23+
}
24+
25+
func main() {
26+
var s Configuration
27+
err := envconfig.Process("davoop", &s)
28+
if err != nil {
29+
log.Fatal(err.Error())
30+
}
31+
32+
fmt.Println(s)
33+
34+
fs, err := davoop.NewHDFSDir(s.NameNode, s.User, s.Path)
35+
if err != nil {
36+
panic(err)
37+
}
38+
39+
http.Handle("/", &webdav.Server{
40+
Fs: fs,
41+
TrimPrefix: "/",
42+
Listings: s.Listing,
43+
ReadOnly: s.ReadOnly,
44+
})
45+
46+
// log.Println("Listening on http://127.0.0.1:8080")
47+
log.Fatal(http.ListenAndServe(s.Addr, nil))
48+
}

webdav/server.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"io"
77
"io/ioutil"
8+
"log"
89
"math/rand"
910
"mime"
1011
"net/http"
@@ -107,7 +108,7 @@ func IsPushMethod(method string) bool {
107108
}
108109

109110
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
110-
//log.Println("DAV:", r.RemoteAddr, r.Method, r.URL)
111+
log.Println("DAV:", r.RemoteAddr, r.Method, r.URL)
111112

112113
switch r.Method {
113114
case "OPTIONS":
@@ -314,6 +315,10 @@ func (s *Server) doPropfind(w http.ResponseWriter, r *http.Request) {
314315
}
315316

316317
depth := r.Header.Get("Depth")
318+
if depth == "" {
319+
depth = "1"
320+
}
321+
317322
switch depth {
318323
case "0", "1":
319324
case "", "infinity":
@@ -399,7 +404,8 @@ func (s *Server) doPropfind(w http.ResponseWriter, r *http.Request) {
399404
buf.WriteString(`<multistatus xmlns='DAV:'>`)
400405

401406
// TODO: https?
402-
abs := "http://" + r.Host + s.TrimPrefix
407+
// abs := "http://" + r.Host + s.TrimPrefix
408+
abs := ""
403409

404410
for _, p := range paths {
405411
// TODO
@@ -414,7 +420,7 @@ func (s *Server) doPropfind(w http.ResponseWriter, r *http.Request) {
414420
fi, _ := f.Stat()
415421

416422
buf.WriteString(`<response>`)
417-
buf.WriteString(`<href>` + abs + "/" + p + `</href>`)
423+
buf.WriteString(`<href>` + filepath.Join(abs, p) + `</href>`)
418424
buf.WriteString(`<propstat>`)
419425
{
420426
buf.WriteString(`<prop>`)

0 commit comments

Comments
 (0)