summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2013-06-27 17:10:06 +0200
committerYorhel <git@yorhel.nl>2013-06-27 17:10:06 +0200
commit73a6aae5d88360d2fb078f36190ff8bbc151bb0e (patch)
tree6947473f144dd6ff0c79a41a96f320bb5df3cd57
parent52059421be26f94937d85c1fcd5292485f953e68 (diff)
share: Add share_share_fl_path() function
Will be needed for the hashing code to figure out what file to hash. (And later on likely for other purposes, too)
-rw-r--r--src/share/share.c25
-rw-r--r--src/share/share.h3
2 files changed, 28 insertions, 0 deletions
diff --git a/src/share/share.c b/src/share/share.c
index b5495d3..8ffc978 100644
--- a/src/share/share.c
+++ b/src/share/share.c
@@ -35,6 +35,31 @@ share_t *share_share_create() {
}
+void share_share_fl_path(share_t *s, share_fl_t *fl, kstring_t *dest) {
+ assert(!share_fl_isdir(fl));
+
+ /* XXX: Linear search is slow. Maybe maintain a path id -> obj index? */
+ size_t i;
+ for(i=0; i<s->c.paths.n; i++)
+ if(s->c.paths.a[i]->id == fl->pathid)
+ break;
+ assert(i < s->c.paths.n);
+ share_path_t *p = s->c.paths.a[i];
+
+ /* XXX: It'd be a bit faster if we could avoid creating the full virtual
+ * path of *fl, instead only creating the path up to where
+ * p->props.VirtualPath ends. */
+ kputs(p->props.FilesystemPath, dest);
+ size_t fspathlen = dest->l;
+ share_fl_path(fl, dest);
+ size_t vpathlen = strlen(p->props.VirtualPath); /* Includes leading '/' */
+ if(vpathlen > 1) {
+ memmove(dest->s + fspathlen, dest->s + fspathlen + vpathlen, dest->l - fspathlen - vpathlen + 1);
+ dest->l -= vpathlen;
+ }
+}
+
+
void share_share_refresh(share_t *s, char *path) {
/* TODO: If a new scan is requested while one is active, we have two
* options:
diff --git a/src/share/share.h b/src/share/share.h
index 5f0c49f..133c336 100644
--- a/src/share/share.h
+++ b/src/share/share.h
@@ -40,6 +40,9 @@ struct share_t {
share_t *share_share_create();
+/* Appends the filesystem path of a share_fl_t object to dest. */
+void share_share_fl_path(share_t *s, share_fl_t *fl, kstring_t *dest);
+
/* Start a scan on the given path. The buffer holding the path may be
* temporarily modified in-place. */
void share_share_refresh(share_t *s, char *path);