Check-in [b437874cfb]
Overview
Comment:More work on getting children processed
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:b437874cfb5042679c5f37777d8df86ffd85cd97
User & Date: rkeene on 2014-09-09 03:43:05
Other Links: manifest | tags
Context
2014-09-09
03:51
Updated to supply valid linked list for children and added readdir implementation check-in: f31f4f56c6 user: rkeene tags: trunk
03:43
More work on getting children processed check-in: b437874cfb user: rkeene tags: trunk
2014-09-08
20:02
Updated to create contents in SHA1 tree check-in: 074c41c6ce user: rkeene tags: trunk
Changes

Modified appfs.c from [4d722642c3] to [0c5019ef32].

    34     34   	APPFS_CPU_UNKNOWN,
    35     35   	APPFS_CPU_ALL,
    36     36   	APPFS_CPU_AMD64,
    37     37   	APPFS_CPU_I386,
    38     38   	APPFS_CPU_ARM
    39     39   } appfs_cpuArch_t;
    40     40   
           41  +typedef enum {
           42  +	APPFS_PATHTYPE_FILE,
           43  +	APPFS_PATHTYPE_DIRECTORY,
           44  +	APPFS_PATHTYPE_SYMLINK
           45  +} appfs_pathtype_t;
           46  +
    41     47   struct appfs_package {
    42     48   	struct appfs_package *_next;
    43     49   	int counter;
    44     50   
    45         -	char name[128];
           51  +	char name[256];
    46     52   	char version[64];
    47     53   	char sha1[41];
    48     54   	appfs_os_t os;
    49     55   	appfs_cpuArch_t cpuArch;
    50     56   	int isLatest;
    51     57   };
    52     58   
    53     59   struct appfs_site {
    54     60   	struct appfs_site *_next;
    55     61   	int counter;
    56     62   
    57     63   	char name[256];
    58     64   };
           65  +
           66  +struct appfs_children {
           67  +	struct appfs_children *_next;
           68  +	int counter;
           69  +
           70  +	char name[256];
           71  +};
           72  +
           73  +struct appfs_pathinfo {
           74  +	appfs_pathtype_t type;
           75  +	time_t time;
           76  +	union {
           77  +		struct {
           78  +			int childcount;
           79  +		} dir;
           80  +		struct {
           81  +			int executable;
           82  +			off_t size;
           83  +		} file;
           84  +	} typeinfo;
           85  +};
    59     86   
    60     87   static appfs_os_t appfs_convert_os_fromString(const char *os) {
    61     88   	if (strcasecmp(os, "Linux") == 0) {
    62     89   		return(APPFS_OS_LINUX);
    63     90   	}
    64     91   
    65     92   	if (strcasecmp(os, "Darwin") == 0 || strcasecmp(os, "Mac OS") == 0 || strcasecmp(os, "Mac OS X") == 0) {
................................................................................
   140    167   	const char *arg;
   141    168   	va_list argp;
   142    169   	int retval;
   143    170   	int i;
   144    171   
   145    172   	objv = (void *) ckalloc(sizeof(*objv) * objc);
   146    173   	objv[0] = Tcl_NewStringObj(cmd, -1);
          174  +	Tcl_IncrRefCount(objv[0]);
   147    175   
   148    176   	va_start(argp, cmd);
   149    177   	for (i = 1; i < objc; i++) {
   150    178   		arg = va_arg(argp, const char *);
   151    179   		objv[i] = Tcl_NewStringObj(arg, -1);
          180  +		Tcl_IncrRefCount(objv[i]);
   152    181   	}
   153    182   	va_end(argp);
   154    183   
   155    184   	retval = Tcl_EvalObjv(interp, objc, objv, 0);
          185  +
          186  +	for (i = 0; i < objc; i++) {
          187  +		Tcl_DecrRefCount(objv[i]);
          188  +	}
   156    189   
   157    190   	ckfree((void *) objv);
   158    191   
   159    192   	return(retval);
   160    193   }
   161    194   
   162    195   #define appfs_free_list_type(id, type) static void appfs_free_list_ ## id(type *head) { \
................................................................................
   165    198   		next = obj->_next; \
   166    199   		ckfree((void *) obj); \
   167    200   	} \
   168    201   }
   169    202   
   170    203   appfs_free_list_type(site, struct appfs_site)
   171    204   appfs_free_list_type(package, struct appfs_package)
   172         -
          205  +appfs_free_list_type(children, struct appfs_children)
   173    206   
   174    207   static int appfs_getsites_cb(void *_head, int columns, char **values, char **names) {
   175    208   	struct appfs_site **head_p, *obj;
   176    209   
   177    210   	head_p = _head;
   178    211   
   179    212   	obj = (void *) ckalloc(sizeof(*obj));
................................................................................
   286    319   	return(0);
   287    320   }
   288    321   
   289    322   static int appfs_getmanifest(const char *hostname, const char *sha1) {
   290    323   	return(0);
   291    324   }
   292    325   
   293         -#if 0
   294         -static int appfs_parse_path(const char *_path, struct appfs_path *pathinfo) {
   295         -	char *path;
          326  +/* Get information about a path, and optionally list children */
          327  +static int appfs_get_path_info(const char *_path, struct appfs_pathinfo *pathinfo, struct appfs_children **children) {
          328  +	struct appfs_site *sites, *site;
          329  +	struct appfs_children *node;
          330  +	int sites_count;
          331  +	char *path, *hostname, *package;
   296    332   
   297    333   	if (_path == NULL) {
   298    334   		return(-ENOENT);
   299    335   	}
   300    336   
   301    337   	if (_path[0] != '/') {
   302    338   		return(-ENOENT);
   303    339   	}
   304    340   
   305    341   	if (_path[1] == '\0') {
   306    342   		/* Request for the root directory */
          343  +		pathinfo->type = APPFS_PATHTYPE_DIRECTORY;
          344  +		sites = appfs_getsites(&sites_count);
          345  +		pathinfo->typeinfo.dir.childcount = sites_count;
          346  +
          347  +		if (children) {
          348  +			for (site = sites; site; site = site->_next) {
          349  +				node = (void *) ckalloc(sizeof(*node));
          350  +				node->_next = *children;
          351  +				*children = node;
          352  +			}
          353  +		}
          354  +
          355  +		appfs_free_list_site(sites);
          356  +
          357  +		return(0);
   307    358   	}
   308    359   
   309    360   	path = strdup(_path);
   310    361   
   311    362   	hostname = path + 1;
   312    363   	package = strchr(hostname, '/');
   313    364   
   314    365   	if (package == NULL) {
   315    366   		/* Request for a single hostname */
          367  +	} else {
          368  +		*package = '\0';
          369  +		package++;
   316    370   	}
   317         -
   318         -
   319    371   }
   320         -#else
   321         -static int appfs_parse_path(const char *_path) {
   322         -	return(0);
   323         -}
   324         -#endif
   325    372   
   326    373   static int appfs_fuse_getattr(const char *path, struct stat *stbuf) {
          374  +	struct appfs_pathinfo pathinfo;
   327    375   	int res = 0;
   328    376   
   329    377   	APPFS_DEBUG("Enter (path = %s, ...)", path);
   330    378   
   331         -	res = appfs_parse_path(path);
          379  +	res = appfs_get_path_info(path, &pathinfo, NULL);
          380  +	if (res != 0) {
          381  +		return(res);
          382  +	}
   332    383   
   333    384   	memset(stbuf, 0, sizeof(struct stat));
   334    385   
   335         -	stbuf->st_mode = S_IFDIR | 0755;
   336         -	stbuf->st_nlink = 2;
          386  +	stbuf->st_mtime = pathinfo.time;
          387  +	stbuf->st_ctime = pathinfo.time;
          388  +	stbuf->st_atime = pathinfo.time;
          389  +
          390  +	if (pathinfo.type == APPFS_PATHTYPE_DIRECTORY) {
          391  +		stbuf->st_mode = S_IFDIR | 0755;
          392  +		stbuf->st_nlink = 2 + pathinfo.typeinfo.dir.childcount;
          393  +	} else {
          394  +		if (pathinfo.typeinfo.file.executable) {
          395  +			stbuf->st_mode = S_IFREG | 0755;
          396  +		} else {
          397  +			stbuf->st_mode = S_IFREG | 0644;
          398  +		}
          399  +
          400  +		stbuf->st_nlink = 1;
          401  +		stbuf->st_size = pathinfo.typeinfo.file.size;
          402  +	}
   337    403   
   338    404   	return res;
   339    405   }
   340    406   
   341    407   static int appfs_fuse_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) {
   342    408   	APPFS_DEBUG("Enter (path = %s, ...)", path);
   343    409