static void testRelPath(MprTestGroup *gp) { char *path, *absPath; path = mprGetRelPath("Makefile", 0); assert(strcmp(path, "Makefile") == 0); path = mprNormalizePath("../a.b"); assert(strcmp(path, "../a.b") == 0); path = mprGetRelPath("/", 0); assert(mprIsPathRel(path)); assert(strncmp(path, "../", 3) == 0); path = mprGetRelPath("//", 0); assert(mprIsPathRel(path)); assert(strncmp(path, "../", 3) == 0); path = mprGetRelPath("/tmp", 0); assert(mprIsPathRel(path)); assert(strncmp(path, "../", 3) == 0); path = mprGetRelPath("/Unknown/someone/junk", 0); assert(mprIsPathRel(path)); assert(strncmp(path, "../", 3) == 0); path = mprGetRelPath("/Users/mob/junk", 0); assert(mprIsPathRel(path)); assert(strncmp(path, "../", 3) == 0); path = mprGetRelPath("/Users/mob/././../mob/junk", 0); assert(mprIsPathRel(path)); assert(strncmp(path, "../", 3) == 0); path = mprGetRelPath(".", 0); assert(strcmp(path, ".") == 0); path = mprGetRelPath("..", 0); assert(strcmp(path, "..") == 0); path = mprGetRelPath("/Users/mob/github/admin", 0); assert(sstarts(path, "..")); path = mprGetRelPath("/Users/mob/git", 0); path = mprGetRelPath("/Users/mob/git/mpr/test", 0); /* Can't really test the result of this */ absPath = mprGetAbsPath("Makefile"); assert(mprIsPathAbs(absPath)); path = mprGetRelPath(absPath, 0); assert(!mprIsPathAbs(path)); assert(strcmp(path, "Makefile") == 0); #if FUTURE // MOB - problem in that we don't know the cwd when testMpr runs // Test relative to an origin out = mprGetAbsPath("../../out"); cwd = mprGetCurrentPath(); assert(smatch(mprGetRelPath(cwd, out), "../src/test")); #endif }
/* WARNING: GC yield */ PUBLIC int espLoadModule(HttpRoute *route, MprDispatcher *dispatcher, cchar *kind, cchar *source, cchar **errMsg) { EspRoute *eroute; MprModule *mp; cchar *appName, *cache, *cacheName, *canonical, *entry, *module; int isView, recompile; eroute = route->eroute; *errMsg = ""; #if VXWORKS /* Trim the drive for VxWorks where simulated host drives only exist on the target */ source = mprTrimPathDrive(source); #endif canonical = mprGetPortablePath(mprGetRelPath(source, route->home)); appName = eroute->appName; if (eroute->combine) { cacheName = appName; } else { cacheName = mprGetMD5WithPrefix(sfmt("%s:%s", appName, canonical), -1, sjoin(kind, "_", NULL)); } if ((cache = httpGetDir(route, "CACHE")) == 0) { cache = "cache"; } module = mprJoinPathExt(mprJoinPaths(route->home, cache, cacheName, NULL), ME_SHOBJ); lock(esp); if (route->update) { if (mprPathExists(source, R_OK)) { isView = smatch(kind, "view"); if (espModuleIsStale(source, module, &recompile) || (isView && layoutIsStale(eroute, source, module))) { if (recompile) { mprHoldBlocks(source, module, cacheName, NULL); if (!espCompile(route, dispatcher, source, module, cacheName, isView, (char**) errMsg)) { mprReleaseBlocks(source, module, cacheName, NULL); unlock(esp); return MPR_ERR_CANT_WRITE; } mprReleaseBlocks(source, module, cacheName, NULL); } } } } if (mprLookupModule(source) == 0) { if (!mprPathExists(module, R_OK)) { *errMsg = "Module does not exist"; unlock(esp); return MPR_ERR_CANT_FIND; } entry = getModuleEntry(eroute, kind, source, cacheName); if ((mp = mprCreateModule(source, module, entry, route)) == 0) { *errMsg = "Memory allocation error loading module"; unlock(esp); return MPR_ERR_MEMORY; } if (mprLoadModule(mp) < 0) { *errMsg = "Cannot load compiled esp module"; unlock(esp); return MPR_ERR_CANT_READ; } } unlock(esp); return 0; }