2014-10-23 10:39:55 +02:00
|
|
|
package gowebdav
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2014-10-23 13:15:02 +02:00
|
|
|
"os"
|
2014-10-23 10:39:55 +02:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2017-10-05 16:22:10 +02:00
|
|
|
// File is our structure for a given file
|
2014-10-23 13:15:02 +02:00
|
|
|
type File struct {
|
2017-11-26 17:23:14 +01:00
|
|
|
path string
|
|
|
|
name string
|
|
|
|
contentType string
|
|
|
|
size int64
|
|
|
|
modified time.Time
|
|
|
|
etag string
|
|
|
|
isdir bool
|
2014-10-23 13:15:02 +02:00
|
|
|
}
|
|
|
|
|
2017-10-05 16:22:10 +02:00
|
|
|
// Name returns the name of a file
|
2014-10-23 13:15:02 +02:00
|
|
|
func (f File) Name() string {
|
|
|
|
return f.name
|
2014-10-23 10:39:55 +02:00
|
|
|
}
|
|
|
|
|
2017-11-26 17:23:14 +01:00
|
|
|
// ContentType returns the content type of a file
|
|
|
|
func (f File) ContentType() string {
|
|
|
|
return f.contentType
|
|
|
|
}
|
|
|
|
|
2017-10-05 16:22:10 +02:00
|
|
|
// Size returns the size of a file
|
2014-10-23 13:15:02 +02:00
|
|
|
func (f File) Size() int64 {
|
|
|
|
return f.size
|
|
|
|
}
|
|
|
|
|
2017-10-05 16:22:10 +02:00
|
|
|
// Mode will return the mode of a given file
|
2014-10-23 13:15:02 +02:00
|
|
|
func (f File) Mode() os.FileMode {
|
2014-10-24 09:29:03 +02:00
|
|
|
// TODO check webdav perms
|
2014-10-23 13:15:02 +02:00
|
|
|
if f.isdir {
|
2014-10-24 09:29:03 +02:00
|
|
|
return 0775 | os.ModeDir
|
2014-10-23 13:15:02 +02:00
|
|
|
}
|
2017-10-05 16:22:10 +02:00
|
|
|
|
|
|
|
return 0664
|
2014-10-23 10:39:55 +02:00
|
|
|
}
|
|
|
|
|
2017-10-05 16:22:10 +02:00
|
|
|
// ModTime returns the modified time of a file
|
2014-10-23 13:15:02 +02:00
|
|
|
func (f File) ModTime() time.Time {
|
2014-10-23 10:39:55 +02:00
|
|
|
return f.modified
|
|
|
|
}
|
|
|
|
|
2017-11-26 17:23:14 +01:00
|
|
|
// ETag returns the ETag of a file
|
|
|
|
func (f File) ETag() string {
|
|
|
|
return f.etag
|
|
|
|
}
|
|
|
|
|
2017-10-05 16:22:10 +02:00
|
|
|
// IsDir let us see if a given file is a directory or not
|
2014-10-23 13:15:02 +02:00
|
|
|
func (f File) IsDir() bool {
|
|
|
|
return f.isdir
|
2014-10-23 10:39:55 +02:00
|
|
|
}
|
|
|
|
|
2017-10-05 16:22:10 +02:00
|
|
|
// Sys ????
|
2014-10-23 13:15:02 +02:00
|
|
|
func (f File) Sys() interface{} {
|
|
|
|
return nil
|
2014-10-23 10:39:55 +02:00
|
|
|
}
|
|
|
|
|
2017-10-05 16:22:10 +02:00
|
|
|
// String lets us see file information
|
2014-10-23 13:15:02 +02:00
|
|
|
func (f File) String() string {
|
|
|
|
if f.isdir {
|
2014-10-27 17:02:00 +01:00
|
|
|
return fmt.Sprintf("Dir : '%s' - '%s'", f.path, f.name)
|
2014-10-23 13:15:02 +02:00
|
|
|
}
|
2017-10-05 16:22:10 +02:00
|
|
|
|
2017-11-26 17:23:14 +01:00
|
|
|
return fmt.Sprintf("File: '%s' SIZE: %d MODIFIED: %s ETAG: %s CTYPE: %s", f.path, f.size, f.modified.String(), f.etag, f.contentType)
|
2014-10-23 10:39:55 +02:00
|
|
|
}
|