diff --git a/client.go b/client.go index f5053b6..585f730 100644 --- a/client.go +++ b/client.go @@ -125,6 +125,53 @@ func (c *Client) ReadDir(path string) ([]os.FileInfo, error) { return files, err } +func (c *Client) Stat(path string) (os.FileInfo, error) { + var f *File = nil + parse := func(resp interface{}) error { + r := resp.(*response) + if p := getProps(r, "200"); p != nil && f == nil { + f = new(File) + f.name = p.Name + f.path = path + + if p.Type.Local == "collection" { + if !strings.HasSuffix(f.path, "/") { + f.path += "/" + } + f.size = 0 + f.modified = time.Unix(0, 0) + f.isdir = true + } else { + f.size = parseInt64(&p.Size) + f.modified = parseModified(&p.Modified) + f.isdir = false + } + } + + r.Props = nil + return nil + } + + err := c.propfind(path, true, + ` + + + + + + + `, + &response{}, + parse) + + if err != nil { + if _, ok := err.(*os.PathError); !ok { + err = &os.PathError{"ReadDir", path, err} + } + } + return f, err +} + func (c *Client) Remove(path string) error { return c.RemoveAll(path) } diff --git a/main/client.go b/main/client.go index 7a8648b..9caef99 100644 --- a/main/client.go +++ b/main/client.go @@ -26,7 +26,7 @@ func Fail(err interface{}) { fmt.Println(" CP | COPY ") fmt.Println(" GET | PULL | READ ") fmt.Println(" PUT | PUSH | WRITE ") - + fmt.Println(" STAT ") } os.Exit(-1) } @@ -73,6 +73,13 @@ func main() { fmt.Println(err) } + case "STAT": + if file, err := c.Stat(path); err == nil { + fmt.Println(file) + } else { + fmt.Println(err) + } + case "GET", "PULL", "READ": if bytes, err := c.Read(path); err == nil { if lidx := strings.LastIndex(path, "/"); lidx != -1 {