src/dbfs/link.c
changeset 36 56427f22e969
parent 35 4f10421681d2
child 37 c3880f3b4de8
--- a/src/dbfs/link.c	Fri Oct 17 20:12:20 2008 +0300
+++ b/src/dbfs/link.c	Tue Oct 21 21:42:17 2008 +0300
@@ -25,7 +25,7 @@
     if (_dbfs_mode(type) != S_IFLNK)
         EERROR(err = EINVAL, "wrong type: %s", type);
     
-    INFO("[dbfs.readlink %p] -> ino=%lu, type=%s, link=%s", req, (unsigned long int) ino, type, link);
+    INFO("\t[dbfs.readlink %p] -> ino=%lu, type=%s, link=%s", req, (unsigned long int) ino, type, link);
     
     // reply
     if ((err = fuse_reply_readlink(req, link)))
@@ -78,3 +78,65 @@
 
 }
 
+#define SETERR(err_var, err_val, bool_val) ((err_var) = bool_val ? (err_val) : 0)
+
+void dbfs_unlink_res (const struct evsql_result_info *res, void *arg) {
+    struct fuse_req *req = arg;
+    int err = 0;
+    
+    // check the results
+    if ((err = dbfs_check_result(res, 1, 0)))
+        goto error;
+        
+    INFO("\t[dbfs.unlink %p] -> OK", req);
+    
+    // reply
+    if ((err = fuse_reply_err(req, 0)))
+        EERROR(err, "fuse_reply_readlink");
+
+error:
+    if (err && (err = fuse_reply_err(req, err)))
+        EWARNING(err, "fuse_reply_err");
+
+    // free
+    evsql_result_free(res);
+}
+
+void dbfs_unlink (struct fuse_req *req, fuse_ino_t parent, const char *name) {
+    struct dbfs *ctx = fuse_req_userdata(req);
+    int err;
+    
+    INFO("[dbfs.unlink %p] parent=%lu, name=%s", req, parent, name);
+
+    const char *sql =
+        "DELETE"
+        " FROM file_tree"
+        " WHERE parent = $1::int4 AND name = $2::varchar";
+
+    static struct evsql_query_params params = EVSQL_PARAMS(EVSQL_FMT_BINARY) {
+        EVSQL_PARAM ( UINT32 ),
+        EVSQL_PARAM ( STRING ),
+
+        EVSQL_PARAMS_END
+    };
+
+    // build params
+    if (SETERR(err, (0
+        ||  evsql_param_uint32(&params, 0, parent)
+        ||  evsql_param_string(&params, 1, name)
+    ), EIO))
+        goto error;
+        
+    // query
+    if (SETERR(err, evsql_query_params(ctx->db, NULL, sql, &params, dbfs_unlink_res, req) == NULL, EIO))
+        goto error;
+
+    // XXX: handle interrupts
+    
+    // wait
+    return;
+
+error:
+    if ((err = fuse_reply_err(req, err)))
+        EWARNING(err, "fuse_reply_err");
+}