Skip to content

Commit

Permalink
lib-fs: Add init function that can use fs string directly
Browse files Browse the repository at this point in the history
This avoids doing splitting the fs driver and args
everywhere and ensures that separators are consistent.
  • Loading branch information
cmouse committed Jul 10, 2017
1 parent cbe4d82 commit c69b62e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/lib-fs/fs-api.c
Expand Up @@ -160,6 +160,17 @@ int fs_init(const char *driver, const char *args,
return 0;
}

int fs_init_from_string(const char *str, const struct fs_settings *set,
struct fs **fs_r, const char **error_r)
{
const char *args = strpbrk(str, " :");
if (args == NULL)
args = "";
else
str = t_strdup_until(str, args++);
return fs_init(str, args, set, fs_r, error_r);
}

void fs_deinit(struct fs **fs)
{
fs_unref(fs);
Expand Down
4 changes: 4 additions & 0 deletions src/lib-fs/fs-api.h
Expand Up @@ -202,6 +202,10 @@ typedef void fs_file_async_callback_t(void *context);
int fs_init(const char *driver, const char *args,
const struct fs_settings *set,
struct fs **fs_r, const char **error_r);
/* helper for fs_init, accepts a filesystem string
that can come directly from config */
int fs_init_from_string(const char *str, const struct fs_settings *set,
struct fs **fs_r, const char **error_r);
/* same as fs_unref() */
void fs_deinit(struct fs **fs);

Expand Down

0 comments on commit c69b62e

Please sign in to comment.