MCPcopy
hub / github.com/gtsteffaniak/filebrowser / getFileInfo

Method getFileInfo

backend/http/webdav.go:56–126  ·  view source on GitHub ↗

getFileInfo retrieves file information with caching and access control requestPath should NOT include user scope - FileInfoFaster applies it internally This function prefers cache, then tries FileInfoFaster which applies access control

(requestPath string, expand bool)

Source from the content-addressed store, hash-verified

54// requestPath should NOT include user scope - FileInfoFaster applies it internally
55// This function prefers cache, then tries FileInfoFaster which applies access control
56func (ffs *filteredFileSystem) getFileInfo(requestPath string, expand bool) (*iteminfo.ExtendedFileInfo, error) {
57 // Initialize cache if needed
58 if ffs.fileInfoCache == nil {
59 ffs.fileInfoCache = make(map[string]*iteminfo.ExtendedFileInfo)
60 }
61
62 // Create cache key (don't modify requestPath itself!)
63 cacheKey := requestPath
64 if expand {
65 cacheKey += ":expand"
66 }
67 if cached, found := ffs.fileInfoCache[cacheKey]; found {
68 return cached, nil
69 }
70
71 // If we're looking for non-expanded but have expanded cached, we can use it
72 // (expanded contains all the same info plus more)
73 if !expand {
74 expandedKey := requestPath + ":expand"
75 if cached, found := ffs.fileInfoCache[expandedKey]; found {
76 return cached, nil
77 }
78 }
79
80 // Call FileInfoFaster with clean requestPath (without scope or cache suffix)
81 // FileInfoFaster applies user scope internally AND enforces access control
82 fileInfo, err := files.FileInfoFaster(utils.FileOptions{
83 Path: requestPath,
84 Source: ffs.source,
85 Expand: expand,
86 ShowHidden: ffs.user.ShowHidden,
87 HideFileExt: ffs.user.HideFileExt,
88 SkipExtendedAttrs: true,
89 FollowSymlinks: true,
90 }, store.Access, ffs.user, store.Share)
91 if err != nil {
92 return nil, err
93 }
94
95 // Cache result using the cache key
96 ffs.fileInfoCache[cacheKey] = fileInfo
97
98 // If we got an expanded directory listing, also cache individual file entries
99 // so Stat calls on those files can use the cache
100 if expand && fileInfo.Type == "directory" {
101 dirPath := requestPath
102 // Cache each file and folder from the directory listing
103 for _, file := range fileInfo.Files {
104 filePath := utils.JoinPathAsUnix(dirPath, file.Name)
105 // Create a minimal ExtendedFileInfo for the file (without expanding its contents)
106 fileEntry := &iteminfo.ExtendedFileInfo{
107 FileInfo: iteminfo.FileInfo{
108 ItemInfo: file.ItemInfo,
109 },
110 }
111 ffs.fileInfoCache[filePath] = fileEntry
112 }
113 for _, folder := range fileInfo.Folders {

Callers 3

checkAccessMethod · 0.95
StatMethod · 0.95
ReaddirMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected