Parcourir la source

webdav: Advertise exclusive write locks in supportedlock property.

Change-Id: I843c13b5a2f8e58c555ec3be09ca1d2d855126c7
Reviewed-on: https://go-review.googlesource.com/10631
Reviewed-by: Nigel Tao <nigeltao@golang.org>
Robert Stepanek il y a 10 ans
Parent
commit
84afb0af00
2 fichiers modifiés avec 41 ajouts et 2 suppressions
  1. 14 2
      webdav/prop.go
  2. 27 0
      webdav/prop_test.go

+ 14 - 2
webdav/prop.go

@@ -141,9 +141,13 @@ var liveProps = map[xml.Name]struct {
 		dir: false,
 	},
 
-	// TODO(nigeltao) Lock properties will be defined later.
+	// TODO: The lockdiscovery property requires LockSystem to list the
+	// active locks on a resource.
 	xml.Name{Space: "DAV:", Local: "lockdiscovery"}: {},
-	xml.Name{Space: "DAV:", Local: "supportedlock"}: {},
+	xml.Name{Space: "DAV:", Local: "supportedlock"}: {
+		findFn: findSupportedLock,
+		dir:    true,
+	},
 }
 
 // TODO(nigeltao) merge props and allprop?
@@ -370,3 +374,11 @@ func findETag(fs FileSystem, ls LockSystem, name string, fi os.FileInfo) (string
 	// with nanosecond granularity.
 	return fmt.Sprintf(`"%x%x"`, fi.ModTime().UnixNano(), fi.Size()), nil
 }
+
+func findSupportedLock(fs FileSystem, ls LockSystem, name string, fi os.FileInfo) (string, error) {
+	return `` +
+		`<lockentry xmlns="DAV:">` +
+		`<lockscope><exclusive/></lockscope>` +
+		`<locktype><write/></locktype>` +
+		`</lockentry>`, nil
+}

+ 27 - 0
webdav/prop_test.go

@@ -70,6 +70,7 @@ func TestMemPS(t *testing.T) {
 				xml.Name{Space: "DAV:", Local: "getcontentlength"},
 				xml.Name{Space: "DAV:", Local: "getlastmodified"},
 				xml.Name{Space: "DAV:", Local: "getcontenttype"},
+				xml.Name{Space: "DAV:", Local: "supportedlock"},
 			},
 		}, {
 			op:   "propname",
@@ -81,6 +82,7 @@ func TestMemPS(t *testing.T) {
 				xml.Name{Space: "DAV:", Local: "getlastmodified"},
 				xml.Name{Space: "DAV:", Local: "getcontenttype"},
 				xml.Name{Space: "DAV:", Local: "getetag"},
+				xml.Name{Space: "DAV:", Local: "supportedlock"},
 			},
 		}},
 	}, {
@@ -106,6 +108,14 @@ func TestMemPS(t *testing.T) {
 				}, {
 					XMLName:  xml.Name{Space: "DAV:", Local: "getcontenttype"},
 					InnerXML: []byte("text/plain; charset=utf-8"),
+				}, {
+					XMLName: xml.Name{Space: "DAV:", Local: "supportedlock"},
+					InnerXML: []byte(`` +
+						`<lockentry xmlns="DAV:">` +
+						`<lockscope><exclusive/></lockscope>` +
+						`<locktype><write/></locktype>` +
+						`</lockentry>`,
+					),
 				}},
 			}},
 		}, {
@@ -131,6 +141,14 @@ func TestMemPS(t *testing.T) {
 				}, {
 					XMLName:  xml.Name{Space: "DAV:", Local: "getetag"},
 					InnerXML: nil, // Calculated during test.
+				}, {
+					XMLName: xml.Name{Space: "DAV:", Local: "supportedlock"},
+					InnerXML: []byte(`` +
+						`<lockentry xmlns="DAV:">` +
+						`<lockscope><exclusive/></lockscope>` +
+						`<locktype><write/></locktype>` +
+						`</lockentry>`,
+					),
 				}},
 			}},
 		}, {
@@ -160,6 +178,14 @@ func TestMemPS(t *testing.T) {
 				}, {
 					XMLName:  xml.Name{Space: "DAV:", Local: "getetag"},
 					InnerXML: nil, // Calculated during test.
+				}, {
+					XMLName: xml.Name{Space: "DAV:", Local: "supportedlock"},
+					InnerXML: []byte(`` +
+						`<lockentry xmlns="DAV:">` +
+						`<lockscope><exclusive/></lockscope>` +
+						`<locktype><write/></locktype>` +
+						`</lockentry>`,
+					),
 				}}}, {
 				Status: http.StatusNotFound,
 				Props: []Property{{
@@ -449,6 +475,7 @@ func TestMemPS(t *testing.T) {
 				xml.Name{Space: "DAV:", Local: "getlastmodified"},
 				xml.Name{Space: "DAV:", Local: "getcontenttype"},
 				xml.Name{Space: "DAV:", Local: "getetag"},
+				xml.Name{Space: "DAV:", Local: "supportedlock"},
 				xml.Name{Space: "foo", Local: "bar"},
 			},
 		}},