Diff

Differences From Artifact [4cd4495e1d]:

To Artifact [799a556739]:


18
19
20
21
22
23
24

25
26
27
28
29
30
31
#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;

};

struct appfs_thread_data globalThread;

typedef enum {
	APPFS_OS_UNKNOWN,
	APPFS_OS_ALL,







>







18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#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_OS_UNKNOWN,
	APPFS_OS_ALL,
674
675
676
677
678
679
680

681
682
683
684
685
686
687
	if (_path[1] == '\0') {
		/* Request for the root directory */
		sites = appfs_getsites(&sites_count);

		pathinfo->type = APPFS_PATHTYPE_DIRECTORY;
		pathinfo->typeinfo.dir.childcount = sites_count;
		pathinfo->hostname[0] = '\0';


		if (children) {
			for (site = sites; site; site = site->_next) {
				node = (void *) ckalloc(sizeof(*node));
				node->_next = *children;
				strcpy(node->name, site->name);
				*children = node;







>







675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
	if (_path[1] == '\0') {
		/* Request for the root directory */
		sites = appfs_getsites(&sites_count);

		pathinfo->type = APPFS_PATHTYPE_DIRECTORY;
		pathinfo->typeinfo.dir.childcount = sites_count;
		pathinfo->hostname[0] = '\0';
		pathinfo->time = globalThread.boottime;

		if (children) {
			for (site = sites; site; site = site->_next) {
				node = (void *) ckalloc(sizeof(*node));
				node->_next = *children;
				strcpy(node->name, site->name);
				*children = node;
716
717
718
719
720
721
722

723
724
725
726
727
728
729
		return(-ENOENT);
	}

	if (packagename == NULL) {
		/* Request for a single hostname */
		pathinfo->type = APPFS_PATHTYPE_DIRECTORY;
		pathinfo->typeinfo.dir.childcount = packages_count;


		if (children) {
			for (package = packages; package; package = package->_next) {
				node = (void *) ckalloc(sizeof(*node));
				node->_next = *children;
				strcpy(node->name, package->name);
				*children = node;







>







718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
		return(-ENOENT);
	}

	if (packagename == NULL) {
		/* Request for a single hostname */
		pathinfo->type = APPFS_PATHTYPE_DIRECTORY;
		pathinfo->typeinfo.dir.childcount = packages_count;
		pathinfo->time = globalThread.boottime;

		if (children) {
			for (package = packages; package; package = package->_next) {
				node = (void *) ckalloc(sizeof(*node));
				node->_next = *children;
				strcpy(node->name, package->name);
				*children = node;
737
738
739
740
741
742
743

744
745
746
747
748
749
750
		return(0);
	}

	os_cpuArch = strchr(packagename, '/');
	if (os_cpuArch == NULL) {
		/* Request for OS and CPU Arch for a specific package */
		pathinfo->type = APPFS_PATHTYPE_DIRECTORY;


		os_cpuArch_count = 0;
		for (package = packages; package; package = package->_next) {
			if (strcmp(package->name, packagename) != 0) {
				APPFS_DEBUG("Skipping package named \"%s\", does not match requested package: \"%s\"", package->name, packagename);

				continue;







>







740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
		return(0);
	}

	os_cpuArch = strchr(packagename, '/');
	if (os_cpuArch == NULL) {
		/* Request for OS and CPU Arch for a specific package */
		pathinfo->type = APPFS_PATHTYPE_DIRECTORY;
		pathinfo->time = globalThread.boottime;

		os_cpuArch_count = 0;
		for (package = packages; package; package = package->_next) {
			if (strcmp(package->name, packagename) != 0) {
				APPFS_DEBUG("Skipping package named \"%s\", does not match requested package: \"%s\"", package->name, packagename);

				continue;
791
792
793
794
795
796
797

798
799
800
801
802
803
804
	}

	os_val = appfs_convert_os_fromString(os);

	if (version == NULL) {
		/* Request for version list for a package on an OS/CPU */
		pathinfo->type = APPFS_PATHTYPE_DIRECTORY;


		version_count = 0;
		for (package = packages; package; package = package->_next) {
			if (strcmp(package->name, packagename) != 0) {
				APPFS_DEBUG("Skipping package named \"%s\", does not match requested package: \"%s\"", package->name, packagename);

				continue;







>







795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
	}

	os_val = appfs_convert_os_fromString(os);

	if (version == NULL) {
		/* Request for version list for a package on an OS/CPU */
		pathinfo->type = APPFS_PATHTYPE_DIRECTORY;
		pathinfo->time = globalThread.boottime;

		version_count = 0;
		for (package = packages; package; package = package->_next) {
			if (strcmp(package->name, packagename) != 0) {
				APPFS_DEBUG("Skipping package named \"%s\", does not match requested package: \"%s\"", package->name, packagename);

				continue;
853
854
855
856
857
858
859

860
861
862
863
864
865
866
		return(-ENOENT);
	}

	APPFS_DEBUG("  ... which hash a hash of %s", package_hash);

	if (strcmp(path, "") == 0) {
		pathinfo->type = APPFS_PATHTYPE_DIRECTORY;

	} else {
		fileinfo_ret = appfs_getfileinfo(hostname, package_hash, path, pathinfo);
		if (fileinfo_ret != 0) {
			free(path_s);

			return(fileinfo_ret);
		}







>







858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
		return(-ENOENT);
	}

	APPFS_DEBUG("  ... which hash a hash of %s", package_hash);

	if (strcmp(path, "") == 0) {
		pathinfo->type = APPFS_PATHTYPE_DIRECTORY;
		pathinfo->time = globalThread.boottime;
	} else {
		fileinfo_ret = appfs_getfileinfo(hostname, package_hash, path, pathinfo);
		if (fileinfo_ret != 0) {
			free(path_s);

			return(fileinfo_ret);
		}
1071
1072
1073
1074
1075
1076
1077

1078
1079
1080
1081
1082
1083
1084

int main(int argc, char **argv) {
	const char *cachedir = APPFS_CACHEDIR;
	char dbfilename[1024];
	int pthread_ret, snprintf_ret, sqlite_ret;

	globalThread.cachedir = cachedir;


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

		return(1);
	}







>







1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091

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);
	}