MCPcopy
hub / github.com/filebrowser/filebrowser / NewFileInfo

Function NewFileInfo

files/file.go:77–107  ·  view source on GitHub ↗

NewFileInfo creates a File object from a path and a given user. This File object will be automatically filled depending on if it is a directory or a file. If it's a video file, it will also detect any subtitles.

(opts *FileOptions)

Source from the content-addressed store, hash-verified

75// object will be automatically filled depending on if it is a directory
76// or a file. If it's a video file, it will also detect any subtitles.
77func NewFileInfo(opts *FileOptions) (*FileInfo, error) {
78 if !opts.Checker.Check(opts.Path) {
79 return nil, os.ErrPermission
80 }
81
82 file, err := stat(opts)
83 if err != nil {
84 return nil, err
85 }
86
87 // Do not expose the name of root directory.
88 if file.Path == "/" {
89 file.Name = ""
90 }
91
92 if opts.Expand {
93 if file.IsDir {
94 if err := file.readListing(opts.Checker, opts.ReadHeader, opts.CalcImgRes); err != nil {
95 return nil, err
96 }
97 return file, nil
98 }
99
100 err = file.detectType(opts.Modify, opts.Content, true, opts.CalcImgRes)
101 if err != nil {
102 return nil, err
103 }
104 }
105
106 return file, err
107}
108
109func stat(opts *FileOptions) (*FileInfo, error) {
110 var file *FileInfo

Callers 13

previewHandlerFunction · 0.92
tusPostHandlerFunction · 0.92
tusHeadHandlerFunction · 0.92
tusPatchHandlerFunction · 0.92
tusDeleteHandlerFunction · 0.92
public.goFile · 0.92
raw.goFile · 0.92
subtitle.goFile · 0.92
resource.goFile · 0.92
resourceDeleteHandlerFunction · 0.92
resourcePostHandlerFunction · 0.92
patchActionFunction · 0.92

Calls 4

statFunction · 0.85
readListingMethod · 0.80
detectTypeMethod · 0.80
CheckMethod · 0.65

Tested by 1