Skip to content

Commit

Permalink
Add configurable target and cache dirs through environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
anaisbetts committed Apr 18, 2008
1 parent e8a14fe commit 2b89010
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
3 changes: 0 additions & 3 deletions README
Expand Up @@ -41,9 +41,6 @@ To run
Known Issues
--------------

* Right now, the source/cache paths are hardcoded - obviously, this is pretty
useless, but you can at least hack it

* vcachefs doesn't do very smart things wrt permissions in the cache folder -
we'll probably have to fix this in the future (but for music/video caching, it
doesn't matter much
2 changes: 1 addition & 1 deletion TODO
Expand Up @@ -5,13 +5,13 @@ Done:
* Async worker thread saving off files
* Save off info in fd table
* Switching from net read to file read mid-file
* Bookkeeping (grok settings, set up cache directory, etc)

Dropped:
* Tag Block cache (media apps cache off this info anyways)


Milestones to 1.0
* Bookkeeping (grok settings, set up cache directory, etc)
* File-based cache
* MRU algorithm when we get cache size pressure
* Extra nonsense
Expand Down
20 changes: 18 additions & 2 deletions src/vcachefs.c
Expand Up @@ -23,6 +23,7 @@

#include <fuse.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
Expand Down Expand Up @@ -240,8 +241,13 @@ static gpointer file_cache_copy_thread(gpointer data)
static void* vcachefs_init(struct fuse_conn_info *conn)
{
struct vcachefs_mount* mount_object = g_new0(struct vcachefs_mount, 1);
mount_object->source_path = "/etc"; /* XXX: Obviously dumb */
mount_object->cache_path = "/home/paul/.vcachefs"; /* XXX: Ditto */
mount_object->source_path = g_strdup(getenv("VCACHEFS_TARGET"));
char* cache = getenv("VCACHEFS_CACHEPATH");
if (cache) {
mount_object->cache_path = g_strdup(cache);
} else {
mount_object->cache_path = g_build_filename(getenv("HOME"), ".vcachefs", NULL);
}

g_thread_init(NULL);

Expand Down Expand Up @@ -285,6 +291,8 @@ static void vcachefs_destroy(void *mount_object_ptr)
g_hash_table_foreach(mount_object->fd_table, trash_fdtable_item, NULL);
g_hash_table_destroy(mount_object->fd_table);
mount_object->fd_table = NULL;
g_free(mount_object->cache_path);
g_free(mount_object->source_path);
g_free(mount_object);
}

Expand Down Expand Up @@ -520,5 +528,13 @@ static struct fuse_operations vcachefs_oper = {

int main(int argc, char *argv[])
{
/* Check for our environment variables
* FIXME: There's got to be a less dumb way to do this */
if (!getenv("VCACHEFS_TARGET")) {
printf(" *** Please set the VCACHEFS_TARGET environment variable to the path that"
"should be mirrored! ***\n");
return -1;
}

return fuse_main(argc, argv, &vcachefs_oper, NULL);
}
4 changes: 2 additions & 2 deletions src/vcachefs.h
Expand Up @@ -29,7 +29,7 @@
/* This object is the per-mount data we carry around with us throughout the
* life of the app until we release it */
struct vcachefs_mount {
const char* source_path;
char* source_path;

/* File descriptor table */
GHashTable* fd_table;
Expand All @@ -40,7 +40,7 @@ struct vcachefs_mount {
GAsyncQueue* file_copy_queue;
GThread* file_copy_thread;
gint quitflag_atomic;
const char* cache_path;
char* cache_path;
};

struct vcachefs_fdentry {
Expand Down

0 comments on commit 2b89010

Please sign in to comment.