|
@@ -48,6 +48,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
} else if h.LockSystem == nil {
|
|
} else if h.LockSystem == nil {
|
|
status, err = http.StatusInternalServerError, errNoLockSystem
|
|
status, err = http.StatusInternalServerError, errNoLockSystem
|
|
} else {
|
|
} else {
|
|
|
|
+ //fmt.Println(r.Method)
|
|
switch r.Method {
|
|
switch r.Method {
|
|
case "OPTIONS":
|
|
case "OPTIONS":
|
|
status, err = h.handleOptions(w, r)
|
|
status, err = h.handleOptions(w, r)
|
|
@@ -56,9 +57,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
case "DELETE":
|
|
case "DELETE":
|
|
status, err = h.handleDelete(w, r)
|
|
status, err = h.handleDelete(w, r)
|
|
case "PUT":
|
|
case "PUT":
|
|
- fmt.Println("PUTTING")
|
|
|
|
status, err = h.handlePut(w, r)
|
|
status, err = h.handlePut(w, r)
|
|
- fmt.Println(status, err)
|
|
|
|
case "MKCOL":
|
|
case "MKCOL":
|
|
status, err = h.handleMkcol(w, r)
|
|
status, err = h.handleMkcol(w, r)
|
|
case "COPY", "MOVE":
|
|
case "COPY", "MOVE":
|
|
@@ -85,6 +84,11 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// Check if the request was from a windows client
|
|
|
|
+func isWindowsClient(r *http.Request) bool {
|
|
|
|
+ return r.Header["User-Agent"] != nil && strings.Contains(r.Header["User-Agent"][0], "Microsoft-WebDAV-MiniRedir")
|
|
|
|
+}
|
|
|
|
+
|
|
func (h *Handler) lock(now time.Time, root string) (token string, status int, err error) {
|
|
func (h *Handler) lock(now time.Time, root string) (token string, status int, err error) {
|
|
token, err = h.LockSystem.Create(now, LockDetails{
|
|
token, err = h.LockSystem.Create(now, LockDetails{
|
|
Root: root,
|
|
Root: root,
|
|
@@ -101,6 +105,11 @@ func (h *Handler) lock(now time.Time, root string) (token string, status int, er
|
|
}
|
|
}
|
|
|
|
|
|
func (h *Handler) confirmLocks(r *http.Request, src, dst string) (release func(), status int, err error) {
|
|
func (h *Handler) confirmLocks(r *http.Request, src, dst string) (release func(), status int, err error) {
|
|
|
|
+ //Ignore lock on Windows
|
|
|
|
+ if isWindowsClient(r) {
|
|
|
|
+ return nil, 200, nil
|
|
|
|
+ }
|
|
|
|
+
|
|
hdr := r.Header.Get("If")
|
|
hdr := r.Header.Get("If")
|
|
if hdr == "" {
|
|
if hdr == "" {
|
|
// An empty If header means that the client hasn't previously created locks.
|
|
// An empty If header means that the client hasn't previously created locks.
|
|
@@ -233,7 +242,11 @@ func (h *Handler) handleDelete(w http.ResponseWriter, r *http.Request) (status i
|
|
if err != nil {
|
|
if err != nil {
|
|
return status, err
|
|
return status, err
|
|
}
|
|
}
|
|
- defer release()
|
|
|
|
|
|
+ defer func() {
|
|
|
|
+ if release != nil {
|
|
|
|
+ release()
|
|
|
|
+ }
|
|
|
|
+ }()
|
|
|
|
|
|
ctx := r.Context()
|
|
ctx := r.Context()
|
|
|
|
|
|
@@ -254,33 +267,28 @@ func (h *Handler) handleDelete(w http.ResponseWriter, r *http.Request) (status i
|
|
return http.StatusNoContent, nil
|
|
return http.StatusNoContent, nil
|
|
}
|
|
}
|
|
|
|
|
|
-// Check if the request was from a windows client
|
|
|
|
-func isWindowsClient(r *http.Request) bool {
|
|
|
|
- return r.Header["User-Agent"] != nil && strings.Contains(r.Header["User-Agent"][0], "Microsoft-WebDAV-MiniRedir")
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
func (h *Handler) handlePut(w http.ResponseWriter, r *http.Request) (status int, err error) {
|
|
func (h *Handler) handlePut(w http.ResponseWriter, r *http.Request) (status int, err error) {
|
|
- fmt.Println("breakpoint 1")
|
|
|
|
reqPath, status, err := h.stripPrefix(r.URL.Path)
|
|
reqPath, status, err := h.stripPrefix(r.URL.Path)
|
|
if err != nil {
|
|
if err != nil {
|
|
return status, err
|
|
return status, err
|
|
}
|
|
}
|
|
- fmt.Println("breakpoint 2")
|
|
|
|
release, status, err := h.confirmLocks(r, reqPath, "")
|
|
release, status, err := h.confirmLocks(r, reqPath, "")
|
|
- if err != nil && !isWindowsClient(r) {
|
|
|
|
|
|
+ if err != nil {
|
|
return status, err
|
|
return status, err
|
|
- } else if err != nil && isWindowsClient(r) {
|
|
|
|
- time.Sleep(1 * time.Second)
|
|
|
|
}
|
|
}
|
|
- defer release()
|
|
|
|
|
|
+
|
|
|
|
+ defer func() {
|
|
|
|
+ if release != nil {
|
|
|
|
+ release()
|
|
|
|
+ }
|
|
|
|
+ }()
|
|
|
|
+
|
|
// TODO(rost): Support the If-Match, If-None-Match headers? See bradfitz'
|
|
// TODO(rost): Support the If-Match, If-None-Match headers? See bradfitz'
|
|
// comments in http.checkEtag.
|
|
// comments in http.checkEtag.
|
|
ctx := r.Context()
|
|
ctx := r.Context()
|
|
- fmt.Println("breakpoint 3")
|
|
|
|
|
|
|
|
f, err := h.FileSystem.OpenFile(ctx, reqPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0775)
|
|
f, err := h.FileSystem.OpenFile(ctx, reqPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0775)
|
|
if err != nil {
|
|
if err != nil {
|
|
- fmt.Println("1", err)
|
|
|
|
return http.StatusNotFound, err
|
|
return http.StatusNotFound, err
|
|
}
|
|
}
|
|
_, copyErr := io.Copy(f, r.Body)
|
|
_, copyErr := io.Copy(f, r.Body)
|
|
@@ -301,7 +309,6 @@ func (h *Handler) handlePut(w http.ResponseWriter, r *http.Request) (status int,
|
|
if err != nil {
|
|
if err != nil {
|
|
return http.StatusInternalServerError, err
|
|
return http.StatusInternalServerError, err
|
|
}
|
|
}
|
|
- fmt.Println(w)
|
|
|
|
w.Header().Set("ETag", etag)
|
|
w.Header().Set("ETag", etag)
|
|
|
|
|
|
return http.StatusCreated, nil
|
|
return http.StatusCreated, nil
|
|
@@ -316,7 +323,11 @@ func (h *Handler) handleMkcol(w http.ResponseWriter, r *http.Request) (status in
|
|
if err != nil {
|
|
if err != nil {
|
|
return status, err
|
|
return status, err
|
|
}
|
|
}
|
|
- defer release()
|
|
|
|
|
|
+ defer func() {
|
|
|
|
+ if release != nil {
|
|
|
|
+ release()
|
|
|
|
+ }
|
|
|
|
+ }()
|
|
|
|
|
|
ctx := r.Context()
|
|
ctx := r.Context()
|
|
|
|
|
|
@@ -374,7 +385,11 @@ func (h *Handler) handleCopyMove(w http.ResponseWriter, r *http.Request) (status
|
|
if err != nil {
|
|
if err != nil {
|
|
return status, err
|
|
return status, err
|
|
}
|
|
}
|
|
- defer release()
|
|
|
|
|
|
+ defer func() {
|
|
|
|
+ if release != nil {
|
|
|
|
+ release()
|
|
|
|
+ }
|
|
|
|
+ }()
|
|
|
|
|
|
// Section 9.8.3 says that "The COPY method on a collection without a Depth
|
|
// Section 9.8.3 says that "The COPY method on a collection without a Depth
|
|
// header must act as if a Depth header with value "infinity" was included".
|
|
// header must act as if a Depth header with value "infinity" was included".
|
|
@@ -394,7 +409,11 @@ func (h *Handler) handleCopyMove(w http.ResponseWriter, r *http.Request) (status
|
|
if err != nil {
|
|
if err != nil {
|
|
return status, err
|
|
return status, err
|
|
}
|
|
}
|
|
- defer release()
|
|
|
|
|
|
+ defer func() {
|
|
|
|
+ if release != nil {
|
|
|
|
+ release()
|
|
|
|
+ }
|
|
|
|
+ }()
|
|
|
|
|
|
// Section 9.9.2 says that "The MOVE method on a collection must act as if
|
|
// Section 9.9.2 says that "The MOVE method on a collection must act as if
|
|
// a "Depth: infinity" header was used on it. A client must not submit a
|
|
// a "Depth: infinity" header was used on it. A client must not submit a
|
|
@@ -613,7 +632,11 @@ func (h *Handler) handleProppatch(w http.ResponseWriter, r *http.Request) (statu
|
|
if err != nil {
|
|
if err != nil {
|
|
return status, err
|
|
return status, err
|
|
}
|
|
}
|
|
- defer release()
|
|
|
|
|
|
+ defer func() {
|
|
|
|
+ if release != nil {
|
|
|
|
+ release()
|
|
|
|
+ }
|
|
|
|
+ }()
|
|
|
|
|
|
ctx := r.Context()
|
|
ctx := r.Context()
|
|
|
|
|