Diff

Differences From Artifact [62dbc078fa]:

To Artifact [4ed6fa78a6]:


1
2

3
4
5
6

7
8
9
10
11
12
13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15


+




+







#define FUSE_USE_VERSION 26

#include <sys/types.h>
#include <sqlite3.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <fuse.h>
#include <tcl.h>

#define APPFS_CACHEDIR "/tmp/appfs-cache"
71
72
73
74
75
76
77

78
79
80
81
82
83
84

85
86
87
88
89
90
91
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95







+







+








	char name[256];
};

struct appfs_pathinfo {
	appfs_pathtype_t type;
	time_t time;
	char hostname[256];
	union {
		struct {
			int childcount;
		} dir;
		struct {
			int executable;
			off_t size;
			char sha1[41];
		} file;
	} typeinfo;
};

static appfs_os_t appfs_convert_os_fromString(const char *os) {
	if (strcasecmp(os, "Linux") == 0) {
		return(APPFS_OS_LINUX);
203
204
205
206
207
208
209
210
211














212
213
214
215
216
217
218
207
208
209
210
211
212
213


214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234







-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+








		return(-1);
	}

	return(0);
}

static int appfs_getfile(const char *hostname, const char *sha1) {
	return(0);
static const char *appfs_getfile(const char *hostname, const char *sha1) {
	char *retval;
	int tcl_ret;

	tcl_ret = appfs_Tcl_Eval(globalThread.interp, 3, "::appfs::download", hostname, sha1);
	if (tcl_ret != TCL_OK) {
		APPFS_DEBUG("Call to ::appfs::download failed: %s", Tcl_GetStringResult(globalThread.interp));

		return(NULL);
	}

	retval = strdup(Tcl_GetStringResult(globalThread.interp));

	return(retval);
}

static int appfs_update_manifest(const char *hostname, const char *sha1) {
	int tcl_ret;

	tcl_ret = appfs_Tcl_Eval(globalThread.interp, 3, "::appfs::getpkgmanifest", hostname, sha1);
	if (tcl_ret != TCL_OK) {
474
475
476
477
478
479
480
481




482

483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510








+
+
+
+

+







		if (!size) {
			size = "0";
		}

		if (!perms) {
			perms = "";
		}

		if (!sha1) {
			sha1 = "";
		}

		pathinfo->typeinfo.file.size = strtoull(size, NULL, 10);
		snprintf(pathinfo->typeinfo.file.sha1, sizeof(pathinfo->typeinfo.file.sha1), "%s", sha1);

		if (strcmp(perms, "x") == 0) {
			pathinfo->typeinfo.file.executable = 1;
		} else {
			pathinfo->typeinfo.file.executable = 0;
		}

590
591
592
593
594
595
596

597
598
599
600
601
602
603
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625







+








	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;
615
616
617
618
619
620
621


622
623
624
625
626
627
628
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652







+
+







	hostname = path + 1;
	packagename = strchr(hostname, '/');

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

	snprintf(pathinfo->hostname, sizeof(pathinfo->hostname), "%s", hostname);

	packages = appfs_getindex(hostname, &packages_count);

	if (packages == NULL || packages_count == 0) {
		APPFS_DEBUG("Unable to fetch package index from %s", hostname);

		free(path_s);
811
812
813
814
815
816
817
818

819
820
821
822

823
824

825
826
827
828
829
830
831
832
833
834
835
836
837

838
839
840
841
842
843



844
845
846
847
848
849
850
851
852
853
854
855

856
857
858






















859
860


861











862







863






864
865
866
867
868
869
870
835
836
837
838
839
840
841

842
843
844
845

846
847

848
849
850
851
852
853
854
855
856
857
858
859
860

861
862
863
864



865
866
867
868
869
870
871
872
873
874
875
876
877
878

879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904


905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926

927
928
929
930
931
932
933
934
935
936
937
938
939







-
+



-
+

-
+












-
+



-
-
-
+
+
+











-
+



+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+

+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
-
+
+
+
+
+
+







	memset(stbuf, 0, sizeof(struct stat));

	stbuf->st_mtime = pathinfo.time;
	stbuf->st_ctime = pathinfo.time;
	stbuf->st_atime = pathinfo.time;

	if (pathinfo.type == APPFS_PATHTYPE_DIRECTORY) {
		stbuf->st_mode = S_IFDIR | 0755;
		stbuf->st_mode = S_IFDIR | 0555;
		stbuf->st_nlink = 2 + pathinfo.typeinfo.dir.childcount;
	} else {
		if (pathinfo.typeinfo.file.executable) {
			stbuf->st_mode = S_IFREG | 0755;
			stbuf->st_mode = S_IFREG | 0555;
		} else {
			stbuf->st_mode = S_IFREG | 0644;
			stbuf->st_mode = S_IFREG | 0444;
		}

		stbuf->st_nlink = 1;
		stbuf->st_size = pathinfo.typeinfo.file.size;
	}

	return res;
}

static int appfs_fuse_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) {
	struct appfs_pathinfo pathinfo;
	struct appfs_children *children, *child;
	int res;
	int retval;

	APPFS_DEBUG("Enter (path = %s, ...)", path);

	res = appfs_get_path_info(path, &pathinfo, &children);
	if (res != 0) {
		return(res);
	retval = appfs_get_path_info(path, &pathinfo, &children);
	if (retval != 0) {
		return(retval);
	}

	filler(buf, ".", NULL, 0);
	filler(buf, "..", NULL, 0);

	for (child = children; child; child = child->_next) {
		filler(buf, child->name, NULL, 0);
	}

	appfs_free_list_children(children);

	return 0;
	return(0);
}

static int appfs_fuse_open(const char *path, struct fuse_file_info *fi) {
	struct appfs_pathinfo pathinfo;
	const char *real_path;
	int fh;
	int gpi_ret;

	APPFS_DEBUG("Enter (path = %s, ...)", path);

	if ((fi->flags & 3) != O_RDONLY) {
                return(-EACCES);
	}

	gpi_ret = appfs_get_path_info(path, &pathinfo, NULL);
	if (gpi_ret != 0) {
		return(gpi_ret);
	}

	if (pathinfo.type == APPFS_PATHTYPE_DIRECTORY) {
		return(-EISDIR);
	}

	real_path = appfs_getfile(pathinfo.hostname, pathinfo.typeinfo.file.sha1);
	if (real_path == NULL) {
	return(-ENOENT);
}
		return(-EIO);
	}

	fh = open(real_path, O_RDONLY);
	free((void *) real_path);
	if (fh < 0) {
		return(-EIO);
	}

	fi->fh = fh;

	return(0);
}

static int appfs_fuse_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) {
	off_t lseek_ret;
	ssize_t read_ret;

	APPFS_DEBUG("Enter (path = %s, ...)", path);

	lseek_ret = lseek(fi->fh, offset, SEEK_SET);
	if (lseek_ret != offset) {
	return(-ENOENT);
		return(-EIO);
	}

	read_ret = read(fi->fh, buf, size);

	return(read_ret);
}

#ifdef APPFS_TEST_DRIVER
static int appfs_test_driver(void) {
	struct appfs_site *sites, *site;
	struct appfs_package *packages, *package;
	struct appfs_children *files, *file;