Ejemplo n.º 1
0
static fs_node_t * finddir_tar_root(fs_node_t *node, char *name) {
	struct tarfs * self = node->device;

	unsigned int offset = 0;
	struct ustar * file = malloc(sizeof(struct ustar));
	while (offset < self->length) {
		int status = ustar_from_offset(self, offset, file);

		if (!status) {
			free(file);
			return NULL;
		}

		char filename_workspace[256];
		memset(filename_workspace, 0, 256);
		strncat(filename_workspace, file->prefix, 155);
		strncat(filename_workspace, file->filename, 100);

		if (count_slashes(filename_workspace)) {
			/* skip */
		} else {
			char * slash = strstr(filename_workspace,"/");
			if (slash) *slash = '\0';
			if (!strcmp(filename_workspace, name)) {
				return file_from_ustar(self, file, offset);
			}
		}

		offset += 512;
		offset += round_to_512(interpret_size(file));
	}

	free(file);
	return NULL;
}
Ejemplo n.º 2
0
static void append_one_rev(const char *av)
{
	struct object_id revkey;
	if (!get_sha1(av, revkey.hash)) {
		append_ref(av, &revkey, 0);
		return;
	}
	if (strchr(av, '*') || strchr(av, '?') || strchr(av, '[')) {
		/* glob style match */
		int saved_matches = ref_name_cnt;

		match_ref_pattern = av;
		match_ref_slash = count_slashes(av);
		for_each_ref(append_matching_ref, NULL);
		if (saved_matches == ref_name_cnt &&
		    ref_name_cnt < MAX_REVS)
			error(_("no matching refs with %s"), av);
		sort_ref_range(saved_matches, ref_name_cnt);
		return;
	}
	die("bad sha1 reference %s", av);
}
Ejemplo n.º 3
0
static int append_matching_ref(const char *refname, const struct object_id *oid,
			       int flag, void *cb_data)
{
	/* we want to allow pattern hold/<asterisk> to show all
	 * branches under refs/heads/hold/, and v0.99.9? to show
	 * refs/tags/v0.99.9a and friends.
	 */
	const char *tail;
	int slash = count_slashes(refname);
	for (tail = refname; *tail && match_ref_slash < slash; )
		if (*tail++ == '/')
			slash--;
	if (!*tail)
		return 0;
	if (wildmatch(match_ref_pattern, tail, 0, NULL))
		return 0;
	if (starts_with(refname, "refs/heads/"))
		return append_head_ref(refname, oid, flag, cb_data);
	if (starts_with(refname, "refs/tags/"))
		return append_tag_ref(refname, oid, flag, cb_data);
	return append_ref(refname, oid, 0);
}
Ejemplo n.º 4
0
static struct dirent * readdir_tarfs(fs_node_t *node, uint32_t index) {
	if (index == 0) {
		struct dirent * out = malloc(sizeof(struct dirent));
		memset(out, 0x00, sizeof(struct dirent));
		out->ino = 0;
		strcpy(out->name, ".");
		return out;
	}

	if (index == 1) {
		struct dirent * out = malloc(sizeof(struct dirent));
		memset(out, 0x00, sizeof(struct dirent));
		out->ino = 0;
		strcpy(out->name, "..");
		return out;
	}

	index -= 2;

	struct tarfs * self = node->device;

	/* Go through each file and pick the ones are at the root */
	/* Root files will have no /, so this is easy */
	unsigned int offset = node->inode;

	/* Read myself */
	struct ustar * file = malloc(sizeof(struct ustar));
	int status = ustar_from_offset(self, node->inode, file);
	char my_filename[256];

	/* Figure out my own filename, with forward slash */
	memset(my_filename, 0, 256);
	strncat(my_filename, file->prefix, 155);
	strncat(my_filename, file->filename, 100);

	while (offset < self->length) {
		ustar_from_offset(self, offset, file);

		if (!status) {
			free(file);
			return NULL;
		}

		char filename_workspace[256];
		memset(filename_workspace, 0, 256);
		strncat(filename_workspace, file->prefix, 155);
		strncat(filename_workspace, file->filename, 100);

		if (startswith(filename_workspace, my_filename)) {
			if (!count_slashes(filename_workspace + strlen(my_filename))) {
				if (strlen(filename_workspace + strlen(my_filename))) {
					if (index == 0) {
						char * slash = strstr(filename_workspace+strlen(my_filename),"/");
						if (slash) *slash = '\0'; /* remove trailing slash */
						struct dirent * out = malloc(sizeof(struct dirent));
						memset(out, 0x00, sizeof(struct dirent));
						out->ino = offset;
						strcpy(out->name, filename_workspace+strlen(my_filename));
						free(file);
						return out;
					} else {
						index--;
					}
				}
			}
		}

		offset += 512;
		offset += round_to_512(interpret_size(file));
	}

	free(file);
	return NULL;
}