Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix pfiles_tags generation in beholddb_mark_recursive().

Ability to set tag character.
  • Loading branch information...
commit c765bb6ae4f8bfaa94532be130230d19906cd9ce 1 parent bb2772f
@cyberhuman authored
Showing with 32 additions and 19 deletions.
  1. +21 −15 beholddb.c
  2. +10 −4 beholdfs.c
  3. +1 −0  beholdfs.h
View
36 beholddb.c
@@ -7,7 +7,7 @@
#include "beholddb.h"
#include "fs.h"
-static void tags_stat(const char *const *tags, size_t *count_p, size_t *count_m, size_t *len_p, size_t *len_m);
+char beholddb_tagchar;
int beholddb_parse_path(const char *path, const char **realpath, const char *const **tags, int invert)
{
@@ -30,7 +30,14 @@ int beholddb_parse_path(const char *path, const char **realpath, const char *con
}
switch (*path)
{
- case '#':
+ default:
+ if (beholddb_tagchar != *path)
+ {
+ *pathptr++ = '/';
+ while (*path && '/' != *path)
+ *pathptr++ = *path++;
+ break;
+ }
do
{
// skip hash sign
@@ -44,19 +51,14 @@ int beholddb_parse_path(const char *path, const char **realpath, const char *con
// handle tag type
++tagcount[*path == '-' ^ !!invert];
// handle glued tags
- while (*path && '/' != *path && '#' != *path)
+ while (*path && '/' != *path && beholddb_tagchar != *path)
*tagsptr++ = *path++;
*tagsptr++ = 0;
- } while ('#' == *path);
+ } while (beholddb_tagchar == *path);
case '/':
- // remove redundant slashes
+ ; // remove redundant slashes
case 0:
- // remove trailing slash
- break;
- default:
- *pathptr++ = '/';
- while (*path && '/' != *path)
- *pathptr++ = *path++;
+ ; // remove trailing slash
}
}
@@ -82,7 +84,7 @@ int beholddb_parse_path(const char *path, const char **realpath, const char *con
++pathptr;
// store tag
tagsarr[tagcount[minus ^ !!invert]++] = pathptr;
- syslog(LOG_DEBUG, "new tag: #%s%s%s", invert ? "!" : "", minus ? "-" : "", pathptr);
+ syslog(LOG_DEBUG, "new tag: %c%s%s%s", beholddb_tagchar, invert ? "!" : "", minus ? "-" : "", pathptr);
}
// terminate tags lists
tagsarr[tagcount[0]] = NULL;
@@ -92,7 +94,6 @@ int beholddb_parse_path(const char *path, const char **realpath, const char *con
pathbuf, tagcount[0], tagcount[1]);
*realpath = pathbuf;
*tags = tagsarr;
- tags_stat(*tags, &tagcount[0], &tagcount[1], NULL, NULL);
return 0;
}
@@ -503,6 +504,7 @@ static int beholddb_mark_recursive(sqlite3 *db, const char *realpath, const char
tags_stat(files_tags, &tagcount_p, &tagcount_m, &tagsize_p, &tagsize_m);
pathbuf = path = (char*)malloc(pathlen + 1 + tagsize_p + tagsize_m);
rows = (const char**)calloc(2 * (tagcount_p + tagcount_m + 2), sizeof(char*));
+ syslog(LOG_DEBUG, "beholddb_mark_recursive: count_p=%d, count_m=%d", tagcount_p, tagcount_m);
memcpy(path, realpath, pathlen);
pathbuf += pathlen;
@@ -524,12 +526,12 @@ static int beholddb_mark_recursive(sqlite3 *db, const char *realpath, const char
pfiles_tags + tagcount_p + 1,
&count,
&size);
- pfiles_tags[count++] = NULL;
+ pfiles_tags[tagcount_p + 1 + count++] = NULL;
// include becomes include for parent's dirs_tags (filtered by 'all files have tag, all dirs have dirs_tag')
// exclude becomes exclude for parent's dirs_tags
pathbuf += size;
- pdirs_tags = pfiles_tags + count;
+ pdirs_tags = pfiles_tags + tagcount_p + 1 + count;
beholddb_exec_select_text(db,
"select t.name from include t "
"where not exists "
@@ -603,7 +605,11 @@ static int beholddb_mark(sqlite3 *db, const char *realpath, const char *const *f
int changes;
+ syslog(LOG_DEBUG, "beholddb_mark(%s)", realpath);
+
//beholddb_begin_transaction(db);
+ beholddb_create_tags(db, files_tags);
+ //?beholddb_create_tags(db, dirs_tags);
beholddb_set_tags(db, files_tags, dirs_tags);
beholddb_mark_worker(db, file, &changes);
//beholddb_commit(db);
View
14 beholdfs.c
@@ -31,14 +31,14 @@ int beholdfs_getattr(const char *path, struct stat *stat)
const char *realpath, *const *tags;
syslog(LOG_DEBUG, "beholdfs_getattr(path=%s)", path);
- //if (!(beholddb_parse_path(path, &realpath, &tags, 0)))
- if (!(beholddb_get_file(path, &realpath, &tags)))
+ if (!(beholddb_parse_path(path, &realpath, &tags, 0)))
+ //if (!(beholddb_get_file(path, &realpath, &tags)))
{
if ((ret = lstat(realpath, stat)))
ret = -errno; else
{
-// if (!S_ISDIR(stat->st_mode) && beholddb_locate_file(realpath, tags))
-// ret = -ENOENT;
+ if (!S_ISDIR(stat->st_mode) && beholddb_locate_file(realpath, tags))
+ ret = -ENOENT;
}
}
syslog(LOG_DEBUG, "beholdfs_getattr: realpath=%s, ret=%d", realpath, ret);
@@ -670,6 +670,9 @@ void *beholdfs_init(struct fuse_conn_info *conn)
fchdir(state->rootdir);
close(state->rootdir);
+
+ extern char beholddb_tagchar;
+ beholddb_tagchar = state->tagchar;
return state;
}
@@ -972,6 +975,9 @@ int main(int argc, char **argv)
struct beholdfs_state *state = (struct beholdfs_state*)malloc(sizeof(struct beholdfs_state));
state->rootdir = rootdir;
+ state->tagchar = '%';
+
+ //setlogmask(LOG_UPTO(LOG_NOTICE));
optind = 0;
//struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
View
1  beholdfs.h
@@ -6,6 +6,7 @@
struct beholdfs_state
{
int rootdir;
+ char tagchar;
};
struct beholdfs_dir
Please sign in to comment.
Something went wrong with that request. Please try again.