Open opens a file for reading Pattern: Direct SQL query - CalDAV stores raw iCalendar content, not file references Note: ForeignKeyData is configured on the column but CalDAV bypasses the JSON API file format
(name string)
| 101 | // Pattern: Direct SQL query - CalDAV stores raw iCalendar content, not file references |
| 102 | // Note: ForeignKeyData is configured on the column but CalDAV bypasses the JSON API file format |
| 103 | func (dcfs *DaptinCaldavFileSystem) Open(name string) (io.ReadCloser, error) { |
| 104 | userID, collectionName, resourceName, isRoot, isUserRoot, isCollectionRoot := dcfs.parsePath(name) |
| 105 | |
| 106 | // Validate user ownership of path |
| 107 | if err := dcfs.validateUserOwnership(userID); err != nil { |
| 108 | return nil, err |
| 109 | } |
| 110 | |
| 111 | if isRoot || isUserRoot || isCollectionRoot { |
| 112 | // Directories cannot be opened for reading |
| 113 | return nil, os.ErrInvalid |
| 114 | } |
| 115 | |
| 116 | transaction, err := dcfs.cruds["calendar"].Connection().Beginx() |
| 117 | if err != nil { |
| 118 | return nil, err |
| 119 | } |
| 120 | defer transaction.Commit() |
| 121 | |
| 122 | // Build rpath: /calendars/{collection_name}/{resource_name} |
| 123 | rpath := path.Join("/calendars", collectionName, resourceName) |
| 124 | |
| 125 | // Use direct SQL to read raw content (not file references) |
| 126 | query, args, err := statementbuilder.Squirrel. |
| 127 | Select("content"). |
| 128 | From("calendar"). |
| 129 | Where(goqu.Ex{ |
| 130 | "rpath": rpath, |
| 131 | "user_account_id": dcfs.sessionUser.UserId, |
| 132 | }). |
| 133 | Prepared(true). |
| 134 | ToSQL() |
| 135 | |
| 136 | if err != nil { |
| 137 | return nil, err |
| 138 | } |
| 139 | |
| 140 | stmt, err := transaction.Preparex(query) |
| 141 | if err != nil { |
| 142 | return nil, err |
| 143 | } |
| 144 | defer stmt.Close() |
| 145 | |
| 146 | var content []byte |
| 147 | err = stmt.QueryRow(args...).Scan(&content) |
| 148 | if err != nil { |
| 149 | return nil, os.ErrNotExist |
| 150 | } |
| 151 | |
| 152 | return &caldavFile{ |
| 153 | content: content, |
| 154 | offset: 0, |
| 155 | }, nil |
| 156 | } |
| 157 | |
| 158 | // Stat returns file/directory information |
| 159 | func (dcfs *DaptinCaldavFileSystem) Stat(name string) (*webdav.FileInfo, error) { |