MCPcopy Create free account
hub / github.com/OpenListTeam/OpenList / patch

Function patch

server/webdav/prop.go:286–349  ·  view source on GitHub ↗

Patch patches the properties of resource name. The return values are constrained in the same manner as DeadPropsHolder.Patch.

(ctx context.Context, ls LockSystem, name string, patches []Proppatch)

Source from the content-addressed store, hash-verified

284// Patch patches the properties of resource name. The return values are
285// constrained in the same manner as DeadPropsHolder.Patch.
286func patch(ctx context.Context, ls LockSystem, name string, patches []Proppatch) ([]Propstat, error) {
287 conflict := false
288loop:
289 for _, patch := range patches {
290 for _, p := range patch.Props {
291 if _, ok := liveProps[p.XMLName]; ok {
292 conflict = true
293 break loop
294 }
295 }
296 }
297 if conflict {
298 pstatForbidden := Propstat{
299 Status: http.StatusForbidden,
300 XMLError: `<D:cannot-modify-protected-property xmlns:D="DAV:"/>`,
301 }
302 pstatFailedDep := Propstat{
303 Status: StatusFailedDependency,
304 }
305 for _, patch := range patches {
306 for _, p := range patch.Props {
307 if _, ok := liveProps[p.XMLName]; ok {
308 pstatForbidden.Props = append(pstatForbidden.Props, Property{XMLName: p.XMLName})
309 } else {
310 pstatFailedDep.Props = append(pstatFailedDep.Props, Property{XMLName: p.XMLName})
311 }
312 }
313 }
314 return makePropstats(pstatForbidden, pstatFailedDep), nil
315 }
316
317 // ------------------------------------------------------------
318 //f, err := fs.OpenFile(ctx, name, os.O_RDWR, 0)
319 //if err != nil {
320 // return nil, err
321 //}
322 //defer f.Close()
323 //if dph, ok := f.(DeadPropsHolder); ok {
324 // ret, err := dph.Patch(patches)
325 // if err != nil {
326 // return nil, err
327 // }
328 // // http://www.webdav.org/specs/rfc4918.html#ELEMENT_propstat says that
329 // // "The contents of the prop XML element must only list the names of
330 // // properties to which the result in the status element applies."
331 // for _, pstat := range ret {
332 // for i, p := range pstat.Props {
333 // pstat.Props[i] = Property{XMLName: p.XMLName}
334 // }
335 // }
336 // return ret, nil
337 //}
338 // ------------------------------------------------------------
339
340 // The file doesn't implement the optional DeadPropsHolder interface, so
341 // all patches are forbidden.
342 pstat := Propstat{Status: http.StatusForbidden}
343 for _, patch := range patches {

Callers 1

handleProppatchMethod · 0.85

Calls 1

makePropstatsFunction · 0.85

Tested by

no test coverage detected