LDLIBS=$(foreach x,$(pkgs),$(LDLIBS_$(x))) -lrt -lpthread ../libeze/libeze.a
PROGS=disk-indexer disk-monitor audio-cmd music-player input-monitor http-monitor index-util
-
+TESTS=test-index
GENERATED=dbmarshal.c dbmarshal.h player.h
all: $(PROGS)
clean:
rm -f $(PROGS)
+ rm -f $(TESTS)
rm -f $(GENERATED)
rm -f *.o *.d
ez_blob_desc DBDISK_DESC[] = {
EZ_BLOB_START(dbdisk, 1, 4),
- EZ_BLOB_STRING(dbdisk, 1, uuid),
- EZ_BLOB_STRING(dbdisk, 2, label),
- EZ_BLOB_STRING(dbdisk, 3, type),
+ EZ_BLOB_INT32(dbdisk, 1, flags),
+ EZ_BLOB_STRING(dbdisk, 2, uuid),
+ EZ_BLOB_STRING(dbdisk, 3, label),
EZ_BLOB_STRING(dbdisk, 4, mount),
};
}
}
-
- if (0) {
- MDB_cursor *cursor;
- MDB_val key = { 0 }, data = { 0 };
- int r;
-
- printf("Known disks:\n");
- mdb_cursor_open(tx, db->disk, &cursor);
- r = mdb_cursor_get(cursor, &key, &data, MDB_FIRST);
- while (r == 0) {
- dbdisk *p = ez_basic_decode(DBDISK_DESC, (ez_blob *)&data);
- p->id = *(int *)key.mv_data;
- printf("id=%d\n", p->id);
- printf(" uuid=%s\n", p->uuid);
- printf(" label=%s\n", p->label);
- printf(" type=%s\n", p->type);
- printf(" mount=%s\n", p->mount);
- ez_blob_free(DBDISK_DESC, p);
- r = mdb_cursor_get(cursor, &key, &data, MDB_NEXT);
- }
- mdb_cursor_close(cursor);
- }
-
res |= mdb_txn_commit(tx);
if (res) {
// path must end in /
// scan all items >= path where there is only 1 / more
- printf("@ dir '%s'\n", start);
-
key.mv_data = start;
key.mv_size = len;
node->file = dbfile_get(tx, db, files[i]);
node->path = node->file->path;
ez_tree_put(tree, node);
-
- printf("%4d: path '%.*s'\n", *(dbid_t *)dat.mv_data, (int)key.mv_size, (char *)key.mv_data);
}
res = mdb_cursor_get(cursor, &key, &dat, MDB_NEXT_MULTIPLE);
}
- printf("res=%d '%s'\n", res, mdb_strerror(res));
mdb_cursor_close(cursor);
fail:
dbdisk *p = ez_basic_decode(DBDISK_DESC, (ez_blob *)&data);
p->id = *(int *)key.mv_data;
printf("id=%d\n", p->id);
+ printf(" flags=%08x\n", p->flags);
printf(" uuid=%s\n", p->uuid);
printf(" label=%s\n", p->label);
- printf(" type=%s\n", p->type);
printf(" mount=%s\n", p->mount);
ez_blob_free(DBDISK_DESC, p);
r = mdb_cursor_get(cursor, &key, &data, MDB_NEXT);
struct dbdisk {
dbid_t id;
+ uint32_t flags;
char *uuid;
char *label;
- char *type;
char *mount; // last mount point
};
+// dbdisk flags
+#define DBDISKF_RECURSIVE 1
+#define DBDISKF_MOUNT 2
+
typedef struct dblist dblist;
struct dblist {
#include <string.h>
#include <locale.h>
+#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <regex.h>
#define HAVE_FSTATAT 1
struct indexer {
-
- char *root;
-
dbindex *db;
dbdisk *disk;
dbtxn *tx; // global transaction for insert 1 disk
- int isnew;
-
ez_list queue;
// files to care about
int unchanged;
};
-
/*
Take a filename and generate some indexing info.
return f;
}
-
-
-
-
-
-
-
struct dir_node {
ez_node ln;
char path[0];
static void indexer_destroy(struct indexer *ix);
-static int indexer_init(struct indexer *ix, dbindex *db, const char *path, const char *uuid) {
+static int indexer_init(struct indexer *ix, dbindex *db, const dbdisk *info) {
int res;
memset(ix, 0, sizeof(*ix));
ez_list_init(&ix->queue);
- ez_list_addtail(&ix->queue, dir_new(path));
-
- ix->root = strdup(path);
-
- res = regcomp(&ix->match, "\\.(mp3|avi|mpeg|mp2|mpg|mp4|mov)$", REG_ICASE | REG_NOSUB | REG_EXTENDED);
+ res = regcomp(&ix->match, "\\.(mp3|avi|mpeg|mp2|mpg|mp4|mov|aac)$", REG_ICASE | REG_NOSUB | REG_EXTENDED);
if (res != 0) {
perror("regcomp");
exit(1);
// Lookup this disk
ix->db = db;
ix->tx = dbindex_begin(db, NULL, 0);
+ ix->disk = dbdisk_get_uuid(ix->tx, db, info->uuid);
- ix->disk = dbdisk_get_uuid(ix->tx, db, uuid);
if (!ix->disk) {
dbdisk *disk;
disk = malloc(sizeof(*ix->disk));
disk->id = 0;
- disk->uuid = strdup(uuid);
- disk->label = strdup("unknown");
- disk->type = strdup("jfs");
- disk->mount = strdup(path);
+ disk->flags = info->flags;
+ disk->uuid = strdup(info->uuid);
+ disk->label = strdup(info->label);
+ disk->mount = strdup(info->mount);
res = dbdisk_add(ix->tx, db, disk);
if (res != 0)
goto fail;
- printf("%8d : add new disk %s\n", disk->id, uuid);
+ printf("%8d : add new disk %s\n", disk->id, disk->uuid);
ix->disk = disk;
} else {
- printf("%8d : add old disk %s\n", ix->disk->id, uuid);
+ printf("%8d : add old disk %s\n", ix->disk->id, ix->disk->uuid);
}
- // FIXME: error handling
+ ez_list_addtail(&ix->queue, dir_new(ix->disk->mount));
return 0;
while ((scan = ez_list_remhead(&ix->queue)))
dir_free(scan);
- free(ix->root);
regfree(&ix->match);
}
while ((scan = ez_list_remhead(&ix->queue))) {
printf("\nscan %s\n", scan->path);
- res = dbfile_node_scan_path(ix->tx, ix->db, ix->disk->id, scan->path + strlen(ix->root), &files);
+ res = dbfile_node_scan_path(ix->tx, ix->db, ix->disk->id, scan->path + strlen(ix->disk->mount), &files);
if (res != 0)
goto fail;
printf("existing: %d\n", ez_tree_size(&files));
if (res == 0) {
if (S_ISREG(st.st_mode)) {
if (regexec(&ix->match, ep->d_name, 0, NULL, 0) == 0) {
- if ((res = indexer_add_file(ix, &st, name, name + strlen(ix->root), &files)))
+ if ((res = indexer_add_file(ix, &st, name, name + strlen(ix->disk->mount), &files)))
goto fail;
count++;
if ((count % 1000) == 0)
indexer_info(ix);
}
- } else if (S_ISDIR(st.st_mode)) {
+ } else if (S_ISDIR(st.st_mode) && (ix->disk->flags & DBDISKF_RECURSIVE)) {
ez_list_addtail(&ix->queue, dir_new(name));
} else if (S_ISLNK(st.st_mode)) {
// softlinks are ignored for simplicity reasons
printf("Indexer: scanning '%s'.\n", disk->mount);
- res = indexer_init(&ix, db, disk->mount, disk->uuid);
+ res = indexer_init(&ix, db, disk);
if (res == 0) {
res = indexer_scan(&ix);
free(m->disk.uuid);
free(m->disk.label);
- free(m->disk.type);
free(m->disk.mount);
free(m);
md->dev = strdup(dev);
md->disk.uuid = strdup(uuid);
- md->disk.type = strdup(type);
+ md->disk.flags = DBDISKF_RECURSIVE | DBDISKF_MOUNT;
md->disk.label = plabel ? strdup(label) : NULL;
md->disk.mount = mountp;
dbscan scan;
for (dbdisk *disk = dbscan_disk(tx, &scan, db, 0); disk; disk = dbscan_disk_next(&scan)) {
- printf("did=%4d uuid='%s' type='%s' label='%s' mount='%s'\n", disk->id, disk->uuid, disk->type, disk->label, disk->mount);
+ printf("did=%4d flags=%08x uuid='%s' label='%s' mount='%s'\n", disk->id, disk->flags, disk->uuid, disk->label, disk->mount);
dbdisk_free(disk);
}
dbscan_free(&scan);
#include "dbindex.h"
#include "notify.h"
+static void usage(const char *self) {
+ printf("usage: %s [-d dbdir]\n"
+ " add [-r] uuid mount | update uuid | shuffle | quit\n", self);
+}
+
int main(int argc, char **argv) {
- if (argc > 1) {
- notify_t q = notify_writer_new(NOTIFY_INDEXER);
-
- if (q) {
- if (strcmp(argv[1], "quit") == 0) {
- notify_msg_send(q, NOTIFY_QUIT, 0, 0);
- } else if (strcmp(argv[1], "shuffle") == 0) {
- notify_msg_send(q, NOTIFY_SHUFFLE, 0, 0);
- } else if (strcmp(argv[1], "add") == 0 && argc == 4) {
+ const char *self = argv[0];
+ notify_t q = notify_writer_new(NOTIFY_INDEXER);
+ const char *cmd = "";
+
+ if (q) {
+ if (argc > 1) {
+ cmd = argv[1];
+ argc -= 2;
+ argv += 2;
+ }
+
+ if (strcmp(cmd, "quit") == 0) {
+ notify_msg_send(q, NOTIFY_QUIT, 0, 0);
+ } else if (strcmp(cmd, "shuffle") == 0) {
+ notify_msg_send(q, NOTIFY_SHUFFLE, 0, 0);
+ } else if (strcmp(cmd, "add") == 0) {
+ uint32_t flags = 0;
+
+ if (argc > 1 && strcmp(argv[0], "-r") == 0) {
+ flags = DBDISKF_RECURSIVE;
+ argc--;
+ argv++;
+ }
+
+ if (argc == 2) {
dbdisk disk = {
- .uuid = argv[2],
+ .flags = flags,
+ .uuid = argv[0],
.label = "system",
- .type = "system",
- .mount = argv[3]
+ .mount = argv[1]
};
notify_msg_send(q, NOTIFY_DISK_ADD, 0, &disk);
+ } else {
+ usage(self);
}
- notify_close(q);
+ } else if (strcmp(cmd, "update") == 0 && argc == 1) {
+ dbdisk disk = {
+ .uuid = argv[0],
+ .label = "",
+ .mount = "",
+ };
+ notify_msg_send(q, NOTIFY_DISK_ADD, 0, &disk);
} else {
- fprintf(stderr, "error: Unable to open IPC channel\n");
+ usage(self);
}
+ notify_close(q);
+ } else {
+ fprintf(stderr, "error: Unable to open IPC channel\n");
}
return 0;