From b076a43f305248b5a9c2e38bd45bcfb50ae5ef3e Mon Sep 17 00:00:00 2001 From: zicla Date: Thu, 25 Apr 2019 16:33:04 +0800 Subject: [PATCH] Try to compare the diff of encoding/xml. --- rest/dav/file.go | 50 ----------------------------------------------- rest/dav_model.go | 14 ++++++++++++- 2 files changed, 13 insertions(+), 51 deletions(-) delete mode 100644 rest/dav/file.go diff --git a/rest/dav/file.go b/rest/dav/file.go deleted file mode 100644 index 1e5bc38..0000000 --- a/rest/dav/file.go +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2014 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package dav - -import ( - "context" - "io" - "net/http" - "os" - "path" -) - -// SlashClean is equivalent to but slightly more efficient than -// path.Clean("/" + name). -func SlashClean(name string) string { - if name == "" || name[0] != '/' { - name = "/" + name - } - return path.Clean(name) -} - -// A FileSystem implements access to a collection of named files. The elements -// in a file path are separated by slash ('/', U+002F) characters, regardless -// of host operating system convention. -// -// Each method has the same semantics as the os package's function of the same -// name. -// -// Note that the os.Rename documentation says that "OS-specific restrictions -// might apply". In particular, whether or not renaming a file or directory -// overwriting another existing file or directory is an error is OS-dependent. -type FileSystem interface { - Mkdir(ctx context.Context, name string, perm os.FileMode) error - OpenFile(ctx context.Context, name string, flag int, perm os.FileMode) (File, error) - RemoveAll(ctx context.Context, name string) error - Rename(ctx context.Context, oldName, newName string) error - Stat(ctx context.Context, name string) (os.FileInfo, error) -} - -// A File is returned by a FileSystem's OpenFile method and can be served by a -// Handler. -// -// A File may optionally implement the DeadPropsHolder interface, if it can -// load and save dead properties. -type File interface { - http.File - io.Writer -} diff --git a/rest/dav_model.go b/rest/dav_model.go index ab9e306..47c2870 100644 --- a/rest/dav_model.go +++ b/rest/dav_model.go @@ -4,6 +4,7 @@ import ( "encoding/xml" "fmt" "net/http" + "path" "strconv" "tank/rest/dav" ) @@ -17,6 +18,17 @@ type LiveProp struct { dir bool } + +// SlashClean is equivalent to but slightly more efficient than +// path.Clean("/" + name). +func SlashClean(name string) string { + if name == "" || name[0] != '/' { + name = "/" + name + } + return path.Clean(name) +} + + //所有的动态属性定义及其值的获取方式 var LivePropMap = map[xml.Name]LiveProp{ {Space: "DAV:", Local: "resourcetype"}: { @@ -31,7 +43,7 @@ var LivePropMap = map[xml.Name]LiveProp{ }, {Space: "DAV:", Local: "displayname"}: { findFn: func(user *User, matter *Matter) string { - if dav.SlashClean(matter.Name) == "/" { + if SlashClean(matter.Name) == "/" { return "" } else { return dav.EscapeXML(matter.Name)