MCPcopy
hub / github.com/daptin/daptin / Stat

Method Stat

server/resource/caldav_filesystem.go:159–227  ·  view source on GitHub ↗

Stat returns file/directory information

(name string)

Source from the content-addressed store, hash-verified

157
158// Stat returns file/directory information
159func (dcfs *DaptinCaldavFileSystem) Stat(name string) (*webdav.FileInfo, error) {
160 userID, collectionName, resourceName, isRoot, isUserRoot, isCollectionRoot := dcfs.parsePath(name)
161
162 // Validate user ownership first
163 if err := dcfs.validateUserOwnership(userID); err != nil {
164 return nil, err
165 }
166
167 if isRoot || isUserRoot || isCollectionRoot {
168 // Directory
169 return &webdav.FileInfo{
170 Path: name,
171 Size: 0,
172 ModTime: time.Now(),
173 IsDir: true,
174 }, nil
175 }
176
177 // File - check if exists
178 transaction, err := dcfs.cruds["calendar"].Connection().Beginx()
179 if err != nil {
180 return nil, err
181 }
182 defer transaction.Commit()
183
184 rpath := path.Join("/calendars", collectionName, resourceName)
185
186 // Use direct SQL to read raw content and timestamps
187 query, args, err := statementbuilder.Squirrel.
188 Select("content", goqu.L("COALESCE(updated_at, created_at)").As("mod_time")).
189 From("calendar").
190 Where(goqu.Ex{
191 "rpath": rpath,
192 "user_account_id": dcfs.sessionUser.UserId,
193 }).
194 Prepared(true).
195 ToSQL()
196
197 if err != nil {
198 return nil, err
199 }
200
201 stmt, err := transaction.Preparex(query)
202 if err != nil {
203 return nil, err
204 }
205 defer stmt.Close()
206
207 var content []byte
208 var modTimeStr string
209 err = stmt.QueryRow(args...).Scan(&content, &modTimeStr)
210 if err != nil {
211 return nil, os.ErrNotExist
212 }
213
214 // Parse the time string from SQLite
215 modTime, err := time.Parse("2006-01-02 15:04:05", modTimeStr)
216 if err != nil {

Callers 15

mainFunction · 0.80
verifyFileInCloudFunction · 0.80
PathExistsAndIsFolderFunction · 0.80
AssetRouteHandlerFunction · 0.80
isFileModifiedFunction · 0.80
SetupNoRouteRouterFunction · 0.80
CreateFaviconEndpointFunction · 0.80
serveStaticAssetFunction · 0.80
ChangeDirectoryMethod · 0.80
GetFileInfoMethod · 0.80
GetFileStatFunction · 0.80

Calls 10

parsePathMethod · 0.95
validateUserOwnershipMethod · 0.95
ScanMethod · 0.80
ParseMethod · 0.80
BeginxMethod · 0.65
ConnectionMethod · 0.65
SelectMethod · 0.65
PreparexMethod · 0.65
CloseMethod · 0.65
QueryRowMethod · 0.65

Tested by

no test coverage detected