MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / Setattr

Method Setattr

cmd/cql-fuse/node.go:154–201  ·  view source on GitHub ↗

Setattr modifies node metadata. This includes changing the size.

(
	ctx context.Context, req *fuse.SetattrRequest, resp *fuse.SetattrResponse,
)

Source from the content-addressed store, hash-verified

152
153// Setattr modifies node metadata. This includes changing the size.
154func (n *Node) Setattr(
155 ctx context.Context, req *fuse.SetattrRequest, resp *fuse.SetattrResponse,
156) error {
157 if !req.Valid.Size() {
158 // We can exit early since only setting the size is implemented.
159 return nil
160 }
161
162 if !n.isRegular() {
163 // Setting the size is only available on regular files.
164 return fuse.Errno(syscall.EINVAL)
165 }
166
167 if req.Size > maxSize {
168 // Too big.
169 return fuse.Errno(syscall.EFBIG)
170 }
171
172 n.mu.Lock()
173 defer n.mu.Unlock()
174
175 if req.Size == n.Size {
176 // Nothing to do.
177 return nil
178 }
179
180 // Store the current size in case we need to rollback.
181 originalSize := n.Size
182
183 // Wrap everything inside a transaction.
184 err := client.ExecuteTx(ctx, n.cfs.db, nil /* txopts */, func(tx *sql.Tx) error {
185 // Resize blocks as needed.
186 if err := resizeBlocks(tx, n.ID, n.Size, req.Size); err != nil {
187 return err
188 }
189
190 n.Size = req.Size
191 return updateNode(tx, n)
192 })
193
194 if err != nil {
195 // Reset our size.
196 log.Print(err)
197 n.Size = originalSize
198 return err
199 }
200 return nil
201}
202
203// Lookup looks up a specific entry in the receiver,
204// which must be a directory. Lookup should return a Node

Callers

nothing calls this directly

Calls 5

isRegularMethod · 0.95
ExecuteTxFunction · 0.92
resizeBlocksFunction · 0.85
updateNodeFunction · 0.85
PrintMethod · 0.80

Tested by

no test coverage detected