summaryrefslogtreecommitdiff
path: root/pgsql.c
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2012-04-13 10:07:46 +0200
committerAndreas Baumann <abaumann@yahoo.com>2012-04-13 10:07:46 +0200
commitf873bf42db96ca494f8c0fff7838c30b84b1849e (patch)
treea1dc3a7a426d354765386684a9d89582d056d0fd /pgsql.c
parent24d3992039adc8f346c481084fdcfd1eea19eca7 (diff)
downloadpgfuse-f873bf42db96ca494f8c0fff7838c30b84b1849e.tar.gz
pgfuse-f873bf42db96ca494f8c0fff7838c30b84b1849e.tar.bz2
added unlink for files and corrected rmdir
Diffstat (limited to 'pgsql.c')
-rw-r--r--pgsql.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/pgsql.c b/pgsql.c
index 29fea0b..bcec422 100644
--- a/pgsql.c
+++ b/pgsql.c
@@ -18,6 +18,7 @@
#include "pgsql.h"
#include <string.h> /* for strlen, memcpy, strcmp */
+#include <stdlib.h> /* for atoi */
#include <syslog.h> /* for ERR_XXX */
#include <errno.h> /* for ENOENT and friends */
@@ -192,6 +193,55 @@ int psql_delete_dir( PGconn *conn, const int id, const char *path )
int lengths[1] = { sizeof( param1 ) };
int binary[1] = { 1 };
PGresult *res;
+ char *iptr;
+ int count;
+
+ res = PQexecParams( conn, "SELECT COUNT(*) FROM dir where parent_id=$1::int4",
+ 1, NULL, values, lengths, binary, 0 );
+
+ if( PQresultStatus( res ) != PGRES_TUPLES_OK ) {
+ syslog( LOG_ERR, "Error in psql_delete_dir for path '%s': %s", path, PQerrorMessage( conn ) );
+ PQclear( res );
+ return -EIO;
+ }
+
+ if( PQntuples( res ) != 1 ) {
+ syslog( LOG_ERR, "Expecting COUNT(*) to return 1 tupe, weird!" );
+ PQclear( res );
+ return -EIO;
+ }
+
+ iptr = PQgetvalue( res, 0, 0 );
+ count = atoi( iptr );
+
+ if( count > 0 ) {
+ PQclear( res );
+ return -ENOTEMPTY;
+ }
+
+ PQclear( res );
+
+ res = PQexecParams( conn, "DELETE FROM dir where id=$1::int4",
+ 1, NULL, values, lengths, binary, 1 );
+
+ if( PQresultStatus( res ) != PGRES_COMMAND_OK ) {
+ syslog( LOG_ERR, "Error in psql_delete_dir for path '%s': %s", path, PQerrorMessage( conn ) );
+ PQclear( res );
+ return -EIO;
+ }
+
+ PQclear( res );
+
+ return 0;
+}
+
+int psql_delete_file( PGconn *conn, const int id, const char *path )
+{
+ int param1 = htonl( id );
+ const char *values[1] = { (char *)&param1 };
+ int lengths[1] = { sizeof( param1 ) };
+ int binary[1] = { 1 };
+ PGresult *res;
res = PQexecParams( conn, "DELETE FROM dir where id=$1::int4",
1, NULL, values, lengths, binary, 1 );