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

Method remove

cmd/cql-fuse/fs.go:112–143  ·  view source on GitHub ↗

remove removes a node give its name and its parent ID. If 'checkChildren' is true, fails if the node has children.

(ctx context.Context, parentID uint64, name string, checkChildren bool)

Source from the content-addressed store, hash-verified

110// remove removes a node give its name and its parent ID.
111// If 'checkChildren' is true, fails if the node has children.
112func (cfs CFS) remove(ctx context.Context, parentID uint64, name string, checkChildren bool) error {
113 const lookupSQL = `SELECT id FROM fs_namespace WHERE (parentID, name) = (?, ?)`
114 const deleteNamespace = `DELETE FROM fs_namespace WHERE (parentID, name) = (?, ?)`
115 const deleteInode = `DELETE FROM fs_inode WHERE id = ?`
116 const deleteBlock = `DELETE FROM fs_block WHERE id = ?`
117 // Start by looking up the node ID.
118 var id uint64
119 if err := cfs.db.QueryRow(lookupSQL, parentID, name).Scan(&id); err != nil {
120 return err
121 }
122 // Check if there are any children.
123 if checkChildren {
124 if err := checkIsEmpty(cfs.db, id); err != nil {
125 return err
126 }
127 }
128
129 err := client.ExecuteTx(ctx, cfs.db, nil /* txopts */, func(tx *sql.Tx) error {
130 // Delete all entries.
131 if _, err := tx.Exec(deleteNamespace, parentID, name); err != nil {
132 return err
133 }
134 if _, err := tx.Exec(deleteInode, id); err != nil {
135 return err
136 }
137 if _, err := tx.Exec(deleteBlock, id); err != nil {
138 return err
139 }
140 return nil
141 })
142 return err
143}
144
145func (cfs CFS) lookup(parentID uint64, name string) (*Node, error) {
146 return getInode(cfs.db, parentID, name)

Callers 1

RemoveMethod · 0.45

Calls 5

ExecuteTxFunction · 0.92
checkIsEmptyFunction · 0.85
QueryRowMethod · 0.80
ExecMethod · 0.65
ScanMethod · 0.45

Tested by

no test coverage detected