Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Have tagfs_write return size for writing to #LISTEN#

- Closes Issue #7
- Changed operations that just *look* at the base name to use g_str_has_suffix()
  rather than g_strcmp0() with base
- Paranoid setting freed pointers to NULL in some places

Conflicts:

	tagfs.c
  • Loading branch information...
commit 22d53eac449100d2ae7b5d812212ffa5a0c3821d 1 parent b4929a0
Mark Watts authored
Showing with 23 additions and 58 deletions.
  1. +7 −6 query.c
  2. +16 −52 tagfs.c
View
13 query.c
@@ -314,12 +314,6 @@ query_t *parse (const char *s)
char *token = NULL;
GList *seps = g_list_new_charlist(' ', NULL);
Tokenizer *tok = tokenizer_new(seps);
- /*
- struct mallinfo minf = mallinfo();
- log_msg("used space = %d\n", minf.uordblks);
- log_msg("free space = %d\n", minf.fordblks);
- log_msg("total space = %d\n", minf.arena);
- */
tokenizer_set_str_stream(tok, qs);
g_free(qs);
token = tokenizer_next(tok, &sep);
@@ -333,12 +327,19 @@ query_t *parse (const char *s)
}
else // malformatted
{
+ free(qr);
return NULL;
}
g_free(token);
+
token = tokenizer_next(tok, &sep);
qr->command_id = _name_to_code(token, q_commands[qr->table_id]);
g_free(token);
+ if (qr->command_id == -1)
+ {
+ free(qr);
+ return NULL;
+ }
token = tokenizer_next(tok, &sep);
int i = 0;
while (token != NULL && i < 10)
View
68 tagfs.c
@@ -118,8 +118,6 @@ int tagfs_getattr (const char *path, struct stat *statbuf)
{
int retstat = 0;
char *fpath = NULL;
- char *basecopy = NULL;
- char *base = NULL;
char *qstring = NULL;
result_t *res = NULL;
@@ -155,49 +153,14 @@ int tagfs_getattr (const char *path, struct stat *statbuf)
res = NULL;
}
- basecopy = g_strdup(path);
- base = basename(basecopy);
-
- if (g_strcmp0(base, TAGFS_DATA->listen) == 0)
+ if (g_str_has_suffix(path, TAGFS_DATA->listen))
{
statbuf->st_mode = S_IFREG | 0755;
statbuf->st_size = 0;
- g_free(basecopy);
log_stat(statbuf);
return retstat;
}
- if (result_queue_exists(TAGFS_DATA->rqm, base))
- {
- statbuf->st_mode = S_IFREG | 0444;
- // get the size of the "file"
- result_t *res = result_queue_peek(TAGFS_DATA->rqm, base);
- if (res != NULL)
- {
- char *str = tagdb_value_to_str(res->type, &(res->data));
- statbuf->st_size = strlen(str);
- statbuf->st_blksize = 4096;
- g_free(str);
- }
- else
- {
- statbuf->st_size = 0;
- }
- g_free(basecopy);
- log_stat(statbuf);
- return retstat;
- }
-
- // check if the file is a tag
- /*
- if (tagdb_get_tag_code(TAGFS_DATA->db, base) > 0)
- {
- statbuf->st_mode = S_IFDIR | 0755;
- g_free(basecopy);
- return retstat;
- }
- */
-
// Check if it's a file
fpath = get_id_copies_path(path);
if (fpath != NULL)
@@ -269,12 +232,8 @@ int tagfs_open (const char *path, struct fuse_file_info *f_info)
int fd;
log_msg("\ntagfs_open(path\"%s\", f_info=0x%08x)\n",
path, f_info);
- char *basec = g_strdup(path);
- char *base = basename(basec);
- int m = g_strcmp0(base, TAGFS_DATA->listen);
- g_free(basec);
- if (m == 0)
+ if (g_str_has_suffix(path, TAGFS_DATA->listen))
{
char tmp_path[PATH_MAX];
g_snprintf(tmp_path, PATH_MAX, "/tmp/%d-TagFS-LISTEN", fuse_get_context()->uid);
@@ -282,7 +241,7 @@ int tagfs_open (const char *path, struct fuse_file_info *f_info)
f_info->fh = fd;
return retstat;
}
-
+
char *fpath = get_id_copies_path(path);
fd = open(fpath, f_info->flags);
@@ -294,22 +253,24 @@ int tagfs_open (const char *path, struct fuse_file_info *f_info)
int tagfs_write (const char *path, const char *buf, size_t size, off_t offset,
struct fuse_file_info *fi)
{
- char *basecopy = g_strdup(path);
- char *base = basename(basecopy);
log_msg("\ntagfs_write(path=\"%s\", buf=0x%08x \"%s\", size=%d, offset=%lld, f_info=0x%08x)\n",
path, buf, buf, size, offset, fi);
// check if we're writing to the "listen" file
- if (g_strcmp0(base, TAGFS_DATA->listen) == 0)
+ if (g_str_has_suffix(path, TAGFS_DATA->listen))
{
// sanitize the buffer string
char *cmdstr = g_strstrip(g_strdup(buf));
result_t *res = tagdb_query(TAGFS_DATA->db, cmdstr);
- g_free(basecopy);
+ if (res != NULL)
+ {
+ log_msg("tagfs_write #LISTEN# tagdb_query result type=%d\
+ value=%s\n", res->type, tagdb_value_to_str(res->type, &(res->data)));
+ }
g_free(cmdstr);
- return 0;
+ result_destroy(res);
+ return size;
}
- g_free(basecopy);
return pwrite(fi->fh, buf, size, offset);
}
@@ -330,6 +291,8 @@ int tagfs_read (const char *path, char *buffer, size_t size, off_t offset,
int tagfs_flush(const char *path, struct fuse_file_info *fi)
{
int retstat = 0;
+ log_msg("\ntagfs_flush(path=\"%s\", fi=0x%08x)\n",
+ path, fi);
return retstat;
}
@@ -337,9 +300,10 @@ int tagfs_flush(const char *path, struct fuse_file_info *fi)
int tagfs_truncate(const char *path, off_t newsize)
{
int retstat = 0;
- char *fpath = get_id_copies_path(path);
+
log_msg("\ntagfs_truncate(path=\"%s\", newsize=%lld)\n",
path, newsize);
+ char *fpath = get_id_copies_path(path);
if (fpath != NULL)
{
@@ -561,7 +525,7 @@ int tagfs_readdir (const char *path, void *buffer, fuse_fill_dir_t filler,
void tagfs_destroy (void *user_data)
{
- tagdb_save(TAGFS_DATA->db, NULL, "test.types");
+ tagdb_save(TAGFS_DATA->db, NULL, NULL);
}
struct fuse_operations tagfs_oper = {
Please sign in to comment.
Something went wrong with that request. Please try again.