src/fuse/udcFuse/udcFuse.c 1.6
1.6 2009/11/20 17:56:35 angie
Path may now include http auth info (that's the only way of communicating the info to udcFuse) -- if so, strip it out when making the udc cache path.
Index: src/fuse/udcFuse/udcFuse.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/fuse/udcFuse/udcFuse.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -b -B -U 4 -r1.5 -r1.6
--- src/fuse/udcFuse/udcFuse.c 19 Nov 2009 19:07:58 -0000 1.5
+++ src/fuse/udcFuse/udcFuse.c 20 Nov 2009 17:56:35 -0000 1.6
@@ -132,18 +132,49 @@
}
return 0;
}
+#define HTTP_PATH_PREFIX "/http/"
+#define QENCODED_AT_SIGN "Q40"
+
+static int fusePathToUdcPath(const char *path, char *udcPath, size_t udcPathSize)
+/* The udc cache path is almost always just udcDefaultDir() + fuse path,
+ * except when the fuse path includes qEncoded http auth info -- necessary for
+ * reconstructing the URL, but not included in the udc cache path.
+ * Return -1 for problem, 0 for OK. */
+{
+char *httpHost = NULL;
+if (startsWith(HTTP_PATH_PREFIX, path))
+ httpHost = (char *)path + strlen(HTTP_PATH_PREFIX);
+if (httpHost)
+ {
+ char *atSign = strstr(httpHost, QENCODED_AT_SIGN);
+ char *nextSlash = strchr(httpHost, '/');
+ if (atSign != NULL &&
+ (nextSlash == NULL || atSign < nextSlash))
+ {
+ ERR_CATCH_START();
+ safef(udcPath, udcPathSize, "%s" HTTP_PATH_PREFIX "%s",
+ udcDefaultDir(), atSign+strlen(QENCODED_AT_SIGN));
+ ERR_CATCH_END("safef udcPath (skipping auth)");
+ return 0;
+ }
+ }
+ERR_CATCH_START();
+safef(udcPath, udcPathSize, "%s%s", udcDefaultDir(), path);
+ERR_CATCH_END("safef udcPath");
+return 0;
+}
+
static int udcfs_getattr(const char *path, struct stat *stbuf)
/* According to http://sourceforge.net/apps/mediawiki/fuse/index.php?title=FuseInvariants ,
* getattr() is called to test existence before every other command except read, write and
* getattr itself. Give stat of corresponding udc cache file (but make it read-only). */
{
unsigned int pid = pthread_self();
char udcCachePath[4096];
-ERR_CATCH_START();
-safef(udcCachePath, sizeof(udcCachePath), "%s%s", udcDefaultDir(), path);
-ERR_CATCH_END("getattr safef udcCachePath");
+if (fusePathToUdcPath(path, udcCachePath, sizeof(udcCachePath)) < 0)
+ return -1;
int res = stat(udcCachePath, stbuf);
if (res != 0)
{
fprintf(stderr, "...[%d] getattr: stat(%s) failed (%d): %s\n", pid, udcCachePath, res, strerror(errno));
@@ -160,13 +191,11 @@
off_t offset, struct fuse_file_info *fi)
/* Read the corresponding udc cache directory. */
{
unsigned int pid = pthread_self();
-char *udcCacheRoot = udcDefaultDir();
char udcCachePath[4096];
-ERR_CATCH_START();
-safef(udcCachePath, sizeof(udcCachePath), "%s%s", udcCacheRoot, path);
-ERR_CATCH_END("readdir safef udcCachePath");
+if (fusePathToUdcPath(path, udcCachePath, sizeof(udcCachePath)) < 0)
+ return -1;
DIR *dirHandle = opendir(udcCachePath);
if (dirHandle == NULL)
{
fprintf(stderr, "...[%d] readdir: opendir(%s) failed!: %s\n",