Check-in [f66a795908]
Overview
Comment:Updated with basic functionality
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:f66a795908579d168b2cde27bc84a0adde122de1
User & Date: rkeene on 2014-09-09 06:01:49
Other Links: manifest | tags
Context
2014-09-09
06:10
Added executable bit check-in: 99c9d35a89 user: rkeene tags: trunk
06:01
Updated with basic functionality check-in: f66a795908 user: rkeene tags: trunk
03:51
Updated to supply valid linked list for children and added readdir implementation check-in: f31f4f56c6 user: rkeene tags: trunk
Changes

Modified appfs.c from [190e7becb3] to [fb14cea935].

1
2
3
4
5

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
..
35
36
37
38
39
40
41

42
43
44
45
46
47
48
...
187
188
189
190
191
192
193































194
195
196
197
198
199
200
...
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
...
311
312
313
314
315
316
317
318

















319
320
321
322

















































323
324
325
































































































































326
327
328
329
330




331







332
333
334
335
336
337
338
339
340
341
342
343
344


345
346
347
348
349
350
351
352
353
354
355
...
356
357
358
359
360
361
362

363
364
365
366
367















368




































































369


















































370









371

372

373






























374
375
376
377
378
379
380
...
438
439
440
441
442
443
444


445
446
447
448
449
450
451
452
...
456
457
458
459
460
461
462


463
464
465
466
467
468
469
470
471



























472
473
474
475
476
477
478
#define FUSE_USE_VERSION 26

#include <sqlite3.h>
#include <string.h>
#include <stdarg.h>

#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <fuse.h>
#include <tcl.h>

#define APPFS_CACHEDIR "/tmp/appfs-cache"

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

struct appfs_thread_data {
	Tcl_Interp *interp;
	sqlite3 *db;
};

struct appfs_thread_data globalThread;
................................................................................
	APPFS_CPU_ALL,
	APPFS_CPU_AMD64,
	APPFS_CPU_I386,
	APPFS_CPU_ARM
} appfs_cpuArch_t;

typedef enum {

	APPFS_PATHTYPE_FILE,
	APPFS_PATHTYPE_DIRECTORY,
	APPFS_PATHTYPE_SYMLINK
} appfs_pathtype_t;

struct appfs_package {
	struct appfs_package *_next;
................................................................................
		Tcl_DecrRefCount(objv[i]);
	}

	ckfree((void *) objv);

	return(retval);
}
































#define appfs_free_list_type(id, type) static void appfs_free_list_ ## id(type *head) { \
	type *obj, *next; \
	for (obj = head; obj; obj = next) { \
		next = obj->_next; \
		ckfree((void *) obj); \
	} \
................................................................................

	return(0);
}

static struct appfs_package *appfs_getindex(const char *hostname, int *package_count_p) {
	struct appfs_package *head = NULL;
	char *sql;
	int tcl_ret, sqlite_ret;

	if (package_count_p == NULL) {
		return(NULL);
	}

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

		return(NULL);
	}

	sql = sqlite3_mprintf("SELECT package, version, sha1, os, cpuArch, isLatest FROM packages WHERE hostname = %Q;", hostname);
	if (sql == NULL) {
		APPFS_DEBUG("Call to sqlite3_mprintf failed.");

................................................................................
	if (head != NULL) {
		*package_count_p = head->counter + 1;
	}

	return(head);
}

static int appfs_getfile(const char *hostname, const char *sha1) {

















	return(0);
}

static int appfs_getmanifest(const char *hostname, const char *sha1) {

















































	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_site *sites, *site;
	struct appfs_children *node;
	int sites_count;




	char *path, *hostname, *package;








	if (_path == NULL) {
		return(-ENOENT);
	}

	if (_path[0] != '/') {
		return(-ENOENT);
	}

	if (_path[1] == '\0') {
		/* Request for the root directory */
		pathinfo->type = APPFS_PATHTYPE_DIRECTORY;
		sites = appfs_getsites(&sites_count);


		pathinfo->typeinfo.dir.childcount = sites_count;

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

		appfs_free_list_site(sites);

		return(0);
	}

	path = strdup(_path);


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

	if (package == NULL) {















		/* Request for a single hostname */




































































	} else {


















































		*package = '\0';









		package++;

	}

}































static int appfs_fuse_getattr(const char *path, struct stat *stbuf) {
	struct appfs_pathinfo pathinfo;
	int res = 0;

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

................................................................................
	return(-ENOENT);
}

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


	int packages_count = 0, sites_count = 0;

	sites = appfs_getsites(&sites_count);
	printf("Sites:\n");
	for (site = sites; site; site = site->_next) {
		printf("\tname = %s\n", site->name);
	}

................................................................................
	if (packages == NULL || packages_count == 0) {
		fprintf(stderr, "Unable to fetch package index from rkeene.org.\n");

		return(1);
	}

	for (package = packages; package; package = package->_next) {


		printf("Package:\n\tname = %s\n\tversion = %s\n\tsha1 = %s\n\tos = %s\n\tcpuArch = %s\n",
			package->name,
			package->version,
			package->sha1,
			appfs_convert_os_toString(package->os),
			appfs_convert_cpuArch_toString(package->cpuArch)
		);
	}




























	appfs_free_list_package(packages);

	return(0);
}
#else
static struct fuse_operations appfs_oper = {
	.getattr	= appfs_fuse_getattr,





>








|







 







>







 







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







 







|





|
|
<
<







 







|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

|
|
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



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



|
<
>
>
>
>
|
>
>
>
>
>
>
>











<

>
>



<







 







>


|

|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

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

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
|
>
|
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
|







 







>
>









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







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
..
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
...
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
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
...
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322


323
324
325
326
327
328
329
...
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369

370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
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
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
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
576

577
578
579
580
581
582

583
584
585
586
587
588
589
...
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
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
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
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
...
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
...
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
#define FUSE_USE_VERSION 26

#include <sqlite3.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <fuse.h>
#include <tcl.h>

#define APPFS_CACHEDIR "/tmp/appfs-cache"

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

struct appfs_thread_data {
	Tcl_Interp *interp;
	sqlite3 *db;
};

struct appfs_thread_data globalThread;
................................................................................
	APPFS_CPU_ALL,
	APPFS_CPU_AMD64,
	APPFS_CPU_I386,
	APPFS_CPU_ARM
} appfs_cpuArch_t;

typedef enum {
	APPFS_PATHTYPE_INVALID,
	APPFS_PATHTYPE_FILE,
	APPFS_PATHTYPE_DIRECTORY,
	APPFS_PATHTYPE_SYMLINK
} appfs_pathtype_t;

struct appfs_package {
	struct appfs_package *_next;
................................................................................
		Tcl_DecrRefCount(objv[i]);
	}

	ckfree((void *) objv);

	return(retval);
}

static int appfs_update_index(const char *hostname) {
	int tcl_ret;

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

		return(-1);
	}

	return(0);
}

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

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) {
		APPFS_DEBUG("Call to ::appfs::getpkgmanifest failed: %s", Tcl_GetStringResult(globalThread.interp));

		return(-1);
	}

	return(0);
}


#define appfs_free_list_type(id, type) static void appfs_free_list_ ## id(type *head) { \
	type *obj, *next; \
	for (obj = head; obj; obj = next) { \
		next = obj->_next; \
		ckfree((void *) obj); \
	} \
................................................................................

	return(0);
}

static struct appfs_package *appfs_getindex(const char *hostname, int *package_count_p) {
	struct appfs_package *head = NULL;
	char *sql;
	int index_ret, sqlite_ret;

	if (package_count_p == NULL) {
		return(NULL);
	}

	index_ret = appfs_update_index(hostname);
	if (index_ret != 0) {


		return(NULL);
	}

	sql = sqlite3_mprintf("SELECT package, version, sha1, os, cpuArch, isLatest FROM packages WHERE hostname = %Q;", hostname);
	if (sql == NULL) {
		APPFS_DEBUG("Call to sqlite3_mprintf failed.");

................................................................................
	if (head != NULL) {
		*package_count_p = head->counter + 1;
	}

	return(head);
}

static int appfs_getchildren_cb(void *_head, int columns, char **values, char **names) {
	struct appfs_children **head_p, *obj;

	head_p = _head;

	obj = (void *) ckalloc(sizeof(*obj));

	snprintf(obj->name, sizeof(obj->name), "%s", values[0]);

	if (*head_p == NULL) {
		obj->counter = 0;
	} else {
		obj->counter = (*head_p)->counter + 1;
	}

	obj->_next = *head_p;
	*head_p = obj;

	return(0);
	
}


static struct appfs_children *appfs_getchildren(const char *hostname, const char *package_hash, const char *path, int *children_count_p) {
	struct appfs_children *head = NULL;
	char *sql;
	int index_ret, sqlite_ret, manifest_ret;

	if (children_count_p == NULL) {
		return(NULL);
	}

	index_ret = appfs_update_index(hostname);
	if (index_ret != 0) {
		return(NULL);
	}

	manifest_ret = appfs_update_manifest(hostname, package_hash);
	if (manifest_ret != 0) {
		return(NULL);
	}

	sql = sqlite3_mprintf("SELECT file_name FROM files WHERE package_sha1 = %Q AND file_directory = %Q;", package_hash, path);
	if (sql == NULL) {
		APPFS_DEBUG("Call to sqlite3_mprintf failed.");

		return(NULL);
	}

	APPFS_DEBUG("SQL: %s", sql);
	sqlite_ret = sqlite3_exec(globalThread.db, sql, appfs_getchildren_cb, &head, NULL);
	sqlite3_free(sql);

	if (sqlite_ret != SQLITE_OK) {
		APPFS_DEBUG("Call to sqlite3_exec failed.");

		return(NULL);
	}

	if (head != NULL) {
		*children_count_p = head->counter + 1;
	}

	return(head);
}

static int appfs_lookup_package_hash_cb(void *_retval, int columns, char **values, char **names) {
	char **retval = _retval;

	*retval = strdup(values[0]);

	return(0);
}

static char *appfs_lookup_package_hash(const char *hostname, const char *package, appfs_os_t os, appfs_cpuArch_t cpuArch, const char *version) {
	char *sql;
	char *retval = NULL;
	int index_ret, sqlite_ret;

	index_ret = appfs_update_index(hostname);
	if (index_ret != 0) {
		return(NULL);
	}

	sql = sqlite3_mprintf("SELECT sha1 FROM packages WHERE hostname = %Q AND package = %Q AND os = %Q AND cpuArch = %Q AND version = %Q;",
		hostname,
		package,
		appfs_convert_os_toString(os),
		appfs_convert_cpuArch_toString(cpuArch),
		version
	);
	if (sql == NULL) {
		APPFS_DEBUG("Call to sqlite3_mprintf failed.");

		return(NULL);
	}

	APPFS_DEBUG("SQL: %s", sql);
	sqlite_ret = sqlite3_exec(globalThread.db, sql, appfs_lookup_package_hash_cb, &retval, NULL);
	sqlite3_free(sql);

	if (sqlite_ret != SQLITE_OK) {
		APPFS_DEBUG("Call to sqlite3_exec failed.");

		return(NULL);
	}

	return(retval);
}

static int appfs_getfileinfo_cb(void *_pathinfo, int columns, char **values, char **names) {
	struct appfs_pathinfo *pathinfo = _pathinfo;
	const char *type, *time, *source, *size;

	type = values[0];
	time = values[1];
	source = values[2];
	size = values[3];

	pathinfo->time = strtoull(time, NULL, 10);

	if (strcmp(type, "file") == 0) {
		pathinfo->type = APPFS_PATHTYPE_FILE;
		pathinfo->typeinfo.file.executable = 0;
		pathinfo->typeinfo.file.size = strtoull(size, NULL, 10);

		return(0);
	}

	if (strcmp(type, "directory") == 0) {
		pathinfo->type = APPFS_PATHTYPE_DIRECTORY;
		pathinfo->typeinfo.dir.childcount = 0;

		return(0);
	}

	return(0);

	/* Until this is used, prevent the compiler from complaining */
	source = source;
}

static int appfs_getfileinfo(const char *hostname, const char *package_hash, const char *_path, struct appfs_pathinfo *pathinfo) {
	char *directory, *file, *path;
	char *sql;
	int index_ret, sqlite_ret, manifest_ret;

	if (pathinfo == NULL) {
		return(-EIO);
	}

	index_ret = appfs_update_index(hostname);
	if (index_ret != 0) {
		return(-EIO);
	}

	manifest_ret = appfs_update_manifest(hostname, package_hash);
	if (manifest_ret != 0) {
		return(-EIO);
	}

	path = strdup(_path);
	directory = path;
	file = strrchr(path, '/');
	if (file == NULL) {
		file = path;
		directory = "";
	} else {
		*file = '\0';
		file++;
	}

	sql = sqlite3_mprintf("SELECT type, time, source, size FROM files WHERE package_sha1 = %Q AND file_directory = %Q AND file_name = %Q;", package_hash, directory, file);
	if (sql == NULL) {
		APPFS_DEBUG("Call to sqlite3_mprintf failed.");

		free(path);

		return(-EIO);
	}

	free(path);

	pathinfo->type = APPFS_PATHTYPE_INVALID;

	APPFS_DEBUG("SQL: %s", sql);
	sqlite_ret = sqlite3_exec(globalThread.db, sql, appfs_getfileinfo_cb, pathinfo, NULL);
	sqlite3_free(sql);

	if (sqlite_ret != SQLITE_OK) {
		APPFS_DEBUG("Call to sqlite3_exec failed.");

		return(-EIO);
	}

	if (pathinfo->type == APPFS_PATHTYPE_INVALID) {
		return(-ENOENT);
	}

	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_site *sites, *site;
	struct appfs_children *node, *dir_children;

	struct appfs_package *packages, *package;
	appfs_os_t os_val;
	appfs_cpuArch_t cpuArch_val;
	char *hostname, *packagename, *os_cpuArch, *os, *cpuArch, *version;
	char *path, *path_s;
	char *package_hash;
	int sites_count, packages_count, os_cpuArch_count, version_count, files_count;
	int fileinfo_ret;

	if (children) {
		*children = NULL;
	}

	if (_path == NULL) {
		return(-ENOENT);
	}

	if (_path[0] != '/') {
		return(-ENOENT);
	}

	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;

		if (children) {

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

		appfs_free_list_site(sites);

		return(0);
	}

	path = strdup(_path);
	path_s = path;

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

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

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

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

		appfs_free_list_package(packages);

		free(path_s);

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

			os_cpuArch_count++;

			if (children) {
				node = (void *) ckalloc(sizeof(*node));
				node->_next = *children;
				snprintf(node->name, sizeof(node->name), "%s-%s", appfs_convert_os_toString(package->os), appfs_convert_cpuArch_toString(package->cpuArch));
				*children = node;
			}
		}

		appfs_free_list_package(packages);

		free(path_s);

		pathinfo->typeinfo.dir.childcount = os_cpuArch_count;

		return(0);
	}

	*os_cpuArch = '\0';
	os_cpuArch++;

	version = strchr(os_cpuArch, '/');

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

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

		cpuArch_val = appfs_convert_cpuArch_fromString(cpuArch);
	} else {
		cpuArch_val = APPFS_CPU_UNKNOWN;
	}

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

			if (package->os != os_val) {
				continue;
			}

			if (package->cpuArch != cpuArch_val) {
				continue;
			}

			version_count++;

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

		appfs_free_list_package(packages);

		free(path_s);

		pathinfo->typeinfo.dir.childcount = version_count;

		return(0);
	}

	appfs_free_list_package(packages);

	path = strchr(version, '/');
	if (path == NULL) {
		path = "";
	} else {
		*path = '\0';
		path++;
	}

	/* Request for a file in a specific package */
	APPFS_DEBUG("Requesting information for hostname = %s, package = %s, os = %s, cpuArch = %s, version = %s, path = %s", 
		hostname, packagename, os, cpuArch, version, path
	);

	package_hash = appfs_lookup_package_hash(hostname, packagename, os_val, cpuArch_val, version);
	if (package_hash == NULL) {
		free(path_s);

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

	if (pathinfo->type == APPFS_PATHTYPE_DIRECTORY) {
		dir_children = appfs_getchildren(hostname, package_hash, path, &files_count);

		if (dir_children != NULL) {
			pathinfo->typeinfo.dir.childcount = files_count;
		}

		if (children) {
			*children = dir_children;
		}
	}

	free(path_s);

	return(0);
}

static int appfs_fuse_getattr(const char *path, struct stat *stbuf) {
	struct appfs_pathinfo pathinfo;
	int res = 0;

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

................................................................................
	return(-ENOENT);
}

#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;
	char *sha1 = NULL;
	int packages_count = 0, sites_count = 0, files_count;

	sites = appfs_getsites(&sites_count);
	printf("Sites:\n");
	for (site = sites; site; site = site->_next) {
		printf("\tname = %s\n", site->name);
	}

................................................................................
	if (packages == NULL || packages_count == 0) {
		fprintf(stderr, "Unable to fetch package index from rkeene.org.\n");

		return(1);
	}

	for (package = packages; package; package = package->_next) {
		sha1 = package->sha1;

		printf("Package:\n\tname = %s\n\tversion = %s\n\tsha1 = %s\n\tos = %s\n\tcpuArch = %s\n",
			package->name,
			package->version,
			package->sha1,
			appfs_convert_os_toString(package->os),
			appfs_convert_cpuArch_toString(package->cpuArch)
		);
	}

	files = appfs_getchildren("rkeene.org", sha1, "", &files_count);
	if (files == NULL) {
		fprintf(stderr, "Unable to list files in the last package.\n");

		return(1);
	}

	printf("Files:\n");
	for (file = files; file; file = file->_next) {
		printf("\t%s\n", file->name);
	}

	appfs_free_list_children(files);

	files = appfs_getchildren("rkeene.org", sha1, "tcl", &files_count);
	if (files == NULL) {
		fprintf(stderr, "Unable to list files in the last package.\n");

		return(1);
	}

	printf("Files:\n");
	for (file = files; file; file = file->_next) {
		printf("\ttcl/%s\n", file->name);
	}

	appfs_free_list_children(files);
	appfs_free_list_package(packages);

	return(0);
}
#else
static struct fuse_operations appfs_oper = {
	.getattr	= appfs_fuse_getattr,

Modified appfs.tcl from [6d048578b4] to [604641f8e6].

161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
		set fd [open $file]
		set pkgdata [read $fd]
		close $fd

		foreach line [split $pkgdata "\n"] {
			set line [string trim $line]

			if {[string match "*/*" $line]} {
				continue
			}

			if {$line == ""} {
				continue
			}

			set work [split $line ","]

			unset -nocomplain fileInfo







<
<
<
<







161
162
163
164
165
166
167




168
169
170
171
172
173
174
		set fd [open $file]
		set pkgdata [read $fd]
		close $fd

		foreach line [split $pkgdata "\n"] {
			set line [string trim $line]





			if {$line == ""} {
				continue
			}

			set work [split $line ","]

			unset -nocomplain fileInfo