Stat returns file/directory information
(name string)
| 157 | |
| 158 | // Stat returns file/directory information |
| 159 | func (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 { |
no test coverage detected