static FileInfoListPtr GetLsCacheFileList(const char *const item) { int ci; int sortBy; int sortOrder; FileInfoListPtr filp; ci = LsCacheLookup(item); if (ci < 0) { /* This dir was not in the * cache -- go get it. */ Ls(item, 'l', "", NULL); ci = LsCacheLookup(item); if (ci < 0) return NULL; } sortBy = 'n'; /* Sort by filename. */ sortOrder = 'a'; /* Sort in ascending order. */ filp = &gLsCache[ci].fil; SortFileInfoList(filp, sortBy, sortOrder); return filp; } /* GetLsCacheFileList */
/* Saves a directory listing from the given path into the cache. */ static void LsCacheAdd(const char *const itempath, FTPFileInfoListPtr files) { char *cp; int j; /* Never cache empty listings in case of errors */ if (files->nFileInfos == 0) return; j = LsCacheLookup(itempath); if (j >= 0) { /* Directory was already in there; * Replace it with the new * contents. */ FlushLsCacheItem(j); } cp = StrDup(itempath); if (cp == NULL) return; j = gOldestLsCacheItem; (void) memcpy(&gLsCache[j].fil, files, sizeof(FTPFileInfoList)); (void) time(&gLsCache[j].expiration); gLsCache[j].expiration += gLsCacheItemLifetime; gLsCache[j].hits = 0; gLsCache[j].itempath = cp; Trace(1, "ls cache add: %s\n", itempath); /* Increment the pointer. This is a circular array, so if it * hits the end it wraps over to the other side. */ gOldestLsCacheItem++; if (gOldestLsCacheItem >= kLsCacheSize) gOldestLsCacheItem = 0; } /* LsCacheAdd */