Diff

Differences From Artifact [f1b76341ae]:

To Artifact [7ee6ccc5a2]:


     9      9   #include <unistd.h>
    10     10   #include <errno.h>
    11     11   #include <fcntl.h>
    12     12   #include <stdio.h>
    13     13   #include <fuse.h>
    14     14   #include <tcl.h>
    15     15   
           16  +#ifndef APPFS_CACHEDIR
    16     17   #define APPFS_CACHEDIR "/var/cache/appfs"
           18  +#endif
    17     19   
    18     20   #define APPFS_DEBUG(x...) { fprintf(stderr, "[debug] %s:%i:%s: ", __FILE__, __LINE__, __func__); fprintf(stderr, x); fprintf(stderr, "\n"); }
    19     21   
    20     22   static pthread_key_t interpKey;
    21     23   
    22     24   struct appfs_thread_data {
    23     25   	sqlite3 *db;
    24     26   	const char *cachedir;
    25     27   	time_t boottime;
           28  +	const char *platform;
    26     29   };
    27     30   
    28     31   struct appfs_thread_data globalThread;
    29     32   
    30     33   typedef enum {
    31     34   	APPFS_PATHTYPE_INVALID,
    32     35   	APPFS_PATHTYPE_FILE,
................................................................................
   541    544   		}
   542    545   	}
   543    546   
   544    547   	appfs_free_list_children(dir_children);
   545    548   
   546    549   	return(0);
   547    550   }
          551  +
          552  +static int appfs_add_path_child(const char *name, struct appfs_pathinfo *pathinfo, struct appfs_children **children) {
          553  +	struct appfs_children *new_child;
          554  +
          555  +	pathinfo->typeinfo.dir.childcount++;
          556  +
          557  +	if (children) {
          558  +		new_child = (void *) ckalloc(sizeof(*new_child));
          559  +		new_child->_next = *children;
          560  +
          561  +		snprintf(new_child->name, sizeof(new_child->name), "%s", name);
          562  +
          563  +		*children = new_child;
          564  +	}
          565  +
          566  +	return(0);
          567  +}
          568  +
   548    569   /* Get information about a path, and optionally list children */
   549    570   static int appfs_get_path_info(const char *_path, struct appfs_pathinfo *pathinfo, struct appfs_children **children) {
   550    571   	struct appfs_children *dir_children;
   551    572   	char *hostname, *packagename, *os_cpuArch, *os, *cpuArch, *version;
   552    573   	char *path, *path_s;
   553    574   	char *package_hash;
   554    575   	char *sql;
................................................................................
   620    641   	if (os_cpuArch == NULL) {
   621    642   		appfs_update_index(hostname);
   622    643   
   623    644   		sql = sqlite3_mprintf("SELECT DISTINCT os, cpuArch FROM packages WHERE hostname = %Q AND package = %Q;", hostname, packagename);
   624    645   
   625    646   		free(path_s);
   626    647   
   627         -		return(appfs_get_path_info_sql(sql, 2, "%s-%s", pathinfo, children));
          648  +		retval = appfs_get_path_info_sql(sql, 2, "%s-%s", pathinfo, children);
          649  +
          650  +		if (retval != 0) {
          651  +			return(retval);
          652  +		}
          653  +
          654  +		appfs_add_path_child("platform", pathinfo, children);
          655  +
          656  +		return(retval);
   628    657   	}
   629    658   
   630    659   	version = strchr(os_cpuArch, '/');
   631    660   
   632    661   	if (version != NULL) {
   633    662   		*version = '\0';
   634    663   		version++;
................................................................................
   635    664   	}
   636    665   
   637    666   	os = os_cpuArch;
   638    667   	cpuArch = strchr(os_cpuArch, '-');
   639    668   	if (cpuArch) {
   640    669   		*cpuArch = '\0';
   641    670   		cpuArch++;
          671  +	} else {
          672  +		cpuArch = "";
   642    673   	}
   643    674   
   644    675   	if (version == NULL) {
          676  +		if (strcmp(os, "platform") == 0 && strcmp(cpuArch, "") == 0) {
          677  +			pathinfo->type = APPFS_PATHTYPE_SYMLINK;
          678  +			pathinfo->time = globalThread.boottime;
          679  +			pathinfo->typeinfo.dir.childcount = 0;
          680  +			pathinfo->typeinfo.symlink.size = strlen(globalThread.platform);
          681  +
          682  +			snprintf(pathinfo->typeinfo.symlink.source, sizeof(pathinfo->typeinfo.symlink.source), "%s", globalThread.platform);
          683  +
          684  +			free(path_s);
          685  +
          686  +			return(0);
          687  +		}
          688  +
   645    689   		/* Request for version list for a package on an OS/CPU */
   646    690   		appfs_update_index(hostname);
   647    691   
   648    692   		sql = sqlite3_mprintf("SELECT DISTINCT version FROM packages WHERE hostname = %Q AND package = %Q AND os = %Q and cpuArch = %Q;", hostname, packagename, os, cpuArch);
   649    693   
   650    694   		free(path_s);
   651    695   
................................................................................
   879    923   int main(int argc, char **argv) {
   880    924   	const char *cachedir = APPFS_CACHEDIR;
   881    925   	char dbfilename[1024];
   882    926   	int pthread_ret, snprintf_ret, sqlite_ret;
   883    927   
   884    928   	globalThread.cachedir = cachedir;
   885    929   	globalThread.boottime = time(NULL);
          930  +	globalThread.platform = "linux-x86_64";
   886    931   
   887    932   	pthread_ret = pthread_key_create(&interpKey, NULL);
   888    933   	if (pthread_ret != 0) {
   889    934   		fprintf(stderr, "Unable to create TSD key for Tcl.  Aborting.\n");
   890    935   
   891    936   		return(1);
   892    937   	}