Skip to content

Commit

Permalink
fa_scanner: Hide unknown files and factorize some code.
Browse files Browse the repository at this point in the history
  • Loading branch information
andoma committed Apr 30, 2011
1 parent 6061b3e commit 43a845d
Showing 1 changed file with 43 additions and 48 deletions.
91 changes: 43 additions & 48 deletions src/fileaccess/fa_scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,34 @@ quick_analyzer(fa_dir_t *fd, prop_t *contents)
*
*/
static void
deep_analyzer(scanner_t *s)
deep_probe(fa_dir_entry_t *fde)
{
prop_t *metadata;
char buf[URL_MAX];

fde->fde_probestatus = FDE_PROBE_DEEP;

metadata = prop_ref_inc(prop_create(fde->fde_prop, "metadata"));

if(fde->fde_type == CONTENT_DIR) {
fde->fde_type = fa_probe_dir(metadata, fde->fde_url);
} else if(fde->fde_type == CONTENT_FILE) {
fde->fde_type = fa_probe(metadata, fde->fde_url, NULL, 0,
NULL, 0,
fde->fde_statdone ? &fde->fde_stat : NULL, 1);
}

set_type(fde->fde_prop, fde->fde_type);
prop_ref_dec(metadata);
}



/**
*
*/
static void
deep_analyzer(scanner_t *s)
{
fa_dir_entry_t *fde;

/* Empty */
Expand All @@ -236,26 +260,8 @@ deep_analyzer(scanner_t *s)
if(s->s_stop)
break;

if(fde->fde_probestatus == FDE_PROBE_DEEP)
continue;

fde->fde_probestatus = FDE_PROBE_DEEP;

metadata = prop_ref_inc(prop_create(fde->fde_prop, "metadata"));

if(fde->fde_type == CONTENT_DIR) {
fde->fde_type = fa_probe_dir(metadata, fde->fde_url);
} else {
fde->fde_type = fa_probe(metadata, fde->fde_url, NULL, 0,
buf, sizeof(buf),
fde->fde_statdone ? &fde->fde_stat : NULL, 1);

if(fde->fde_type == CONTENT_UNKNOWN)
TRACE(TRACE_DEBUG, "BROWSE",
"File \"%s\" not recognized: %s", fde->fde_url, buf);
}
prop_ref_dec(metadata);
set_type(fde->fde_prop, fde->fde_type);
if(fde->fde_probestatus != FDE_PROBE_DEEP)
deep_probe(fde);
}
}

Expand Down Expand Up @@ -291,31 +297,15 @@ scanner_checkstop(void *opaque)
static void
scanner_entry_setup(scanner_t *s, fa_dir_entry_t *fde)
{
prop_t *metadata;
int r;

if(fde->fde_type == CONTENT_FILE)
fde->fde_type = type_from_filename(fde->fde_filename);

make_prop(fde);

if(fde->fde_type != CONTENT_UNKNOWN) {
metadata = prop_ref_inc(prop_create(fde->fde_prop, "metadata"));
if(fde->fde_type == CONTENT_DIR) {
r = fa_probe_dir(metadata, fde->fde_url);
} else {
r = fa_probe(metadata, fde->fde_url, NULL, 0, NULL, 0,
fde->fde_statdone ? &fde->fde_stat : NULL, 1);
}
prop_ref_dec(metadata);

set_type(fde->fde_prop, r);
fde->fde_type = r;
}
deep_probe(fde);

if(fde->fde_type != CONTENT_UNKNOWN)
if(!prop_set_parent(fde->fde_prop, s->s_nodes))
return; // OK
if(!prop_set_parent(fde->fde_prop, s->s_nodes))
return; // OK

prop_destroy(fde->fde_prop);
fde->fde_prop = NULL;
Expand Down Expand Up @@ -422,8 +412,7 @@ doscan(scanner_t *s)

TAILQ_FOREACH(fde, &fd->fd_entries, fde_link) {
make_prop(fde);
if(fde->fde_type != CONTENT_UNKNOWN)
pv = prop_vec_append(pv, fde->fde_prop);
pv = prop_vec_append(pv, fde->fde_prop);
}

prop_set_parent_vector(pv, s->s_nodes);
Expand Down Expand Up @@ -516,14 +505,20 @@ void
fa_scanner(const char *url, prop_t *model, const char *playme)
{
scanner_t *s = calloc(1, sizeof(scanner_t));

prop_t *source = prop_create(model, "source");

struct prop_nf *pnf;

pnf = prop_nf_create(prop_create(model, "nodes"),
source,
prop_create(model, "filter"),
"node.filename", PROP_NF_AUTODESTROY);

prop_nf_pred_str_add(pnf, "node.type",
PROP_NF_CMP_EQ, "unknown", NULL,
PROP_NF_MODE_EXCLUDE);

prop_nf_release(prop_nf_create(prop_create(model, "nodes"),
source,
prop_create(model, "filter"),
"node.filename", PROP_NF_AUTODESTROY));
prop_nf_release(pnf);

prop_set_int(prop_create(model, "canFilter"), 1);

Expand Down

0 comments on commit 43a845d

Please sign in to comment.