Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alist-org
GitHub Repository: alist-org/alist
Path: blob/main/pkg/gowebdav/file.go
1560 views
1
package gowebdav
2
3
import (
4
"fmt"
5
"os"
6
"time"
7
)
8
9
// File is our structure for a given file
10
type File struct {
11
path string
12
name string
13
contentType string
14
size int64
15
modified time.Time
16
etag string
17
isdir bool
18
}
19
20
// Path returns the full path of a file
21
func (f File) Path() string {
22
return f.path
23
}
24
25
// Name returns the name of a file
26
func (f File) Name() string {
27
return f.name
28
}
29
30
// ContentType returns the content type of a file
31
func (f File) ContentType() string {
32
return f.contentType
33
}
34
35
// Size returns the size of a file
36
func (f File) Size() int64 {
37
return f.size
38
}
39
40
// Mode will return the mode of a given file
41
func (f File) Mode() os.FileMode {
42
// TODO check webdav perms
43
if f.isdir {
44
return 0775 | os.ModeDir
45
}
46
47
return 0664
48
}
49
50
// ModTime returns the modified time of a file
51
func (f File) ModTime() time.Time {
52
return f.modified
53
}
54
55
// ETag returns the ETag of a file
56
func (f File) ETag() string {
57
return f.etag
58
}
59
60
// IsDir let us see if a given file is a directory or not
61
func (f File) IsDir() bool {
62
return f.isdir
63
}
64
65
// Sys ????
66
func (f File) Sys() interface{} {
67
return nil
68
}
69
70
// String lets us see file information
71
func (f File) String() string {
72
if f.isdir {
73
return fmt.Sprintf("Dir : '%s' - '%s'", f.path, f.name)
74
}
75
76
return fmt.Sprintf("File: '%s' SIZE: %d MODIFIED: %s ETAG: %s CTYPE: %s", f.path, f.size, f.modified.String(), f.etag, f.contentType)
77
}
78
79