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)
| 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. |
| 77 | func 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 | |
| 109 | func stat(opts *FileOptions) (*FileInfo, error) { |
| 110 | var file *FileInfo |