create inserts a new node. parentID: inode ID of the parent directory. name: name of the new node node: new node.
(ctx context.Context, parentID uint64, name string, node *Node)
| 91 | // name: name of the new node |
| 92 | // node: new node. |
| 93 | func (cfs CFS) create(ctx context.Context, parentID uint64, name string, node *Node) error { |
| 94 | inode := node.toJSON() |
| 95 | const insertNode = `INSERT INTO fs_inode VALUES (?, ?)` |
| 96 | const insertNamespace = `INSERT INTO fs_namespace VALUES (?, ?, ?)` |
| 97 | |
| 98 | err := client.ExecuteTx(ctx, cfs.db, nil /* txopts */, func(tx *sql.Tx) error { |
| 99 | if _, err := tx.Exec(insertNode, node.ID, inode); err != nil { |
| 100 | return err |
| 101 | } |
| 102 | if _, err := tx.Exec(insertNamespace, parentID, name, node.ID); err != nil { |
| 103 | return err |
| 104 | } |
| 105 | return nil |
| 106 | }) |
| 107 | return err |
| 108 | } |
| 109 | |
| 110 | // remove removes a node give its name and its parent ID. |
| 111 | // If 'checkChildren' is true, fails if the node has children. |