Check-in [7ef423f980]
Overview
Comment:Added support for a "platform" symlink pointing to the current platform
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 7ef423f9801897adf704b60419ba9957747026a8
User & Date: rkeene on 2014-09-18 05:14:17
Other Links: manifest | tags
Context
2014-09-18
17:32
Added inode support (computed, for now) and fixed a memory leak check-in: dd6c402d76 user: rkeene tags: trunk
05:14
Added support for a "platform" symlink pointing to the current platform check-in: 7ef423f980 user: rkeene tags: trunk
2014-09-16
18:21
Removed blank line check-in: 17bbfdc417 user: rkeene tags: trunk
Changes

Modified appfsd.c from [f1b76341ae] to [7ee6ccc5a2].

9
10
11
12
13
14
15

16

17
18
19
20
21
22
23
24
25

26
27
28
29
30
31
32
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <fuse.h>
#include <tcl.h>


#define APPFS_CACHEDIR "/var/cache/appfs"


#define APPFS_DEBUG(x...) { fprintf(stderr, "[debug] %s:%i:%s: ", __FILE__, __LINE__, __func__); fprintf(stderr, x); fprintf(stderr, "\n"); }

static pthread_key_t interpKey;

struct appfs_thread_data {
	sqlite3 *db;
	const char *cachedir;
	time_t boottime;

};

struct appfs_thread_data globalThread;

typedef enum {
	APPFS_PATHTYPE_INVALID,
	APPFS_PATHTYPE_FILE,







>

>









>







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <fuse.h>
#include <tcl.h>

#ifndef APPFS_CACHEDIR
#define APPFS_CACHEDIR "/var/cache/appfs"
#endif

#define APPFS_DEBUG(x...) { fprintf(stderr, "[debug] %s:%i:%s: ", __FILE__, __LINE__, __func__); fprintf(stderr, x); fprintf(stderr, "\n"); }

static pthread_key_t interpKey;

struct appfs_thread_data {
	sqlite3 *db;
	const char *cachedir;
	time_t boottime;
	const char *platform;
};

struct appfs_thread_data globalThread;

typedef enum {
	APPFS_PATHTYPE_INVALID,
	APPFS_PATHTYPE_FILE,
541
542
543
544
545
546
547


















548
549
550
551
552
553
554
		}
	}

	appfs_free_list_children(dir_children);

	return(0);
}


















/* Get information about a path, and optionally list children */
static int appfs_get_path_info(const char *_path, struct appfs_pathinfo *pathinfo, struct appfs_children **children) {
	struct appfs_children *dir_children;
	char *hostname, *packagename, *os_cpuArch, *os, *cpuArch, *version;
	char *path, *path_s;
	char *package_hash;
	char *sql;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
		}
	}

	appfs_free_list_children(dir_children);

	return(0);
}

static int appfs_add_path_child(const char *name, struct appfs_pathinfo *pathinfo, struct appfs_children **children) {
	struct appfs_children *new_child;

	pathinfo->typeinfo.dir.childcount++;

	if (children) {
		new_child = (void *) ckalloc(sizeof(*new_child));
		new_child->_next = *children;

		snprintf(new_child->name, sizeof(new_child->name), "%s", name);

		*children = new_child;
	}

	return(0);
}

/* Get information about a path, and optionally list children */
static int appfs_get_path_info(const char *_path, struct appfs_pathinfo *pathinfo, struct appfs_children **children) {
	struct appfs_children *dir_children;
	char *hostname, *packagename, *os_cpuArch, *os, *cpuArch, *version;
	char *path, *path_s;
	char *package_hash;
	char *sql;
620
621
622
623
624
625
626
627








628
629
630
631
632
633
634
635
636
637
638
639
640
641


642
643
644













645
646
647
648
649
650
651
	if (os_cpuArch == NULL) {
		appfs_update_index(hostname);

		sql = sqlite3_mprintf("SELECT DISTINCT os, cpuArch FROM packages WHERE hostname = %Q AND package = %Q;", hostname, packagename);

		free(path_s);

		return(appfs_get_path_info_sql(sql, 2, "%s-%s", pathinfo, children));








	}

	version = strchr(os_cpuArch, '/');

	if (version != NULL) {
		*version = '\0';
		version++;
	}

	os = os_cpuArch;
	cpuArch = strchr(os_cpuArch, '-');
	if (cpuArch) {
		*cpuArch = '\0';
		cpuArch++;


	}

	if (version == NULL) {













		/* Request for version list for a package on an OS/CPU */
		appfs_update_index(hostname);

		sql = sqlite3_mprintf("SELECT DISTINCT version FROM packages WHERE hostname = %Q AND package = %Q AND os = %Q and cpuArch = %Q;", hostname, packagename, os, cpuArch);

		free(path_s);








|
>
>
>
>
>
>
>
>














>
>



>
>
>
>
>
>
>
>
>
>
>
>
>







641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
	if (os_cpuArch == NULL) {
		appfs_update_index(hostname);

		sql = sqlite3_mprintf("SELECT DISTINCT os, cpuArch FROM packages WHERE hostname = %Q AND package = %Q;", hostname, packagename);

		free(path_s);

		retval = appfs_get_path_info_sql(sql, 2, "%s-%s", pathinfo, children);

		if (retval != 0) {
			return(retval);
		}

		appfs_add_path_child("platform", pathinfo, children);

		return(retval);
	}

	version = strchr(os_cpuArch, '/');

	if (version != NULL) {
		*version = '\0';
		version++;
	}

	os = os_cpuArch;
	cpuArch = strchr(os_cpuArch, '-');
	if (cpuArch) {
		*cpuArch = '\0';
		cpuArch++;
	} else {
		cpuArch = "";
	}

	if (version == NULL) {
		if (strcmp(os, "platform") == 0 && strcmp(cpuArch, "") == 0) {
			pathinfo->type = APPFS_PATHTYPE_SYMLINK;
			pathinfo->time = globalThread.boottime;
			pathinfo->typeinfo.dir.childcount = 0;
			pathinfo->typeinfo.symlink.size = strlen(globalThread.platform);

			snprintf(pathinfo->typeinfo.symlink.source, sizeof(pathinfo->typeinfo.symlink.source), "%s", globalThread.platform);

			free(path_s);

			return(0);
		}

		/* Request for version list for a package on an OS/CPU */
		appfs_update_index(hostname);

		sql = sqlite3_mprintf("SELECT DISTINCT version FROM packages WHERE hostname = %Q AND package = %Q AND os = %Q and cpuArch = %Q;", hostname, packagename, os, cpuArch);

		free(path_s);

879
880
881
882
883
884
885

886
887
888
889
890
891
892
int main(int argc, char **argv) {
	const char *cachedir = APPFS_CACHEDIR;
	char dbfilename[1024];
	int pthread_ret, snprintf_ret, sqlite_ret;

	globalThread.cachedir = cachedir;
	globalThread.boottime = time(NULL);


	pthread_ret = pthread_key_create(&interpKey, NULL);
	if (pthread_ret != 0) {
		fprintf(stderr, "Unable to create TSD key for Tcl.  Aborting.\n");

		return(1);
	}







>







923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
int main(int argc, char **argv) {
	const char *cachedir = APPFS_CACHEDIR;
	char dbfilename[1024];
	int pthread_ret, snprintf_ret, sqlite_ret;

	globalThread.cachedir = cachedir;
	globalThread.boottime = time(NULL);
	globalThread.platform = "linux-x86_64";

	pthread_ret = pthread_key_create(&interpKey, NULL);
	if (pthread_ret != 0) {
		fprintf(stderr, "Unable to create TSD key for Tcl.  Aborting.\n");

		return(1);
	}