From: Not Zed Date: Thu, 30 Dec 2021 22:09:57 +0000 (+1030) Subject: lists fixes and changes X-Git-Url: https://code.zedzone.au/cvs?a=commitdiff_plain;h=46d751bee09d9f61484a330ddac351b54918f938;p=playerz lists fixes and changes fix file delete when file isn't in any list create shuffle playlist from one disk only --- diff --git a/dbindex.c b/dbindex.c index 76d6596..2b17ac4 100644 --- a/dbindex.c +++ b/dbindex.c @@ -498,6 +498,7 @@ int dbdisk_del(dbtxn *txn, dbindex *db, dbdisk *disk) { res = ENOMEM; goto fail; } + printf("dsik %d files %zd\n", disk->id, count); for (int i=0;ilistid, ((struct dblistfile *)data.mv_data)->seq); - if (size >= alloc) { - alloc *= 2; - list = realloc(list, sizeof(*list) * alloc); - } - list[size++] = *(struct dblistfile *)data.mv_data; - - res = mdb_cursor_get(cursor, &key, &data, MDB_NEXT_DUP); - } - mdb_cursor_close(cursor); + if (res == 0) { + printf("set list by file: %d\n", res); + while (res == 0) { + printf(" list: %d @ %d\n", ((struct dblistfile *)data.mv_data)->listid, ((struct dblistfile *)data.mv_data)->seq); + if (size >= alloc) { + alloc *= 2; + list = realloc(list, sizeof(*list) * alloc); + } + list[size++] = *(struct dblistfile *)data.mv_data; - if (res = mdb_del(tx, db->list_by_file, &key, NULL)) - goto fail; + res = mdb_cursor_get(cursor, &key, &data, MDB_NEXT_DUP); + } + mdb_cursor_close(cursor); - printf("list entries: %zd\n", size); - - for (int i=0;iid - }; - printf("delete file %d from list %d @ %d\n", fdata.fileid, list[i].listid, fdata.seq); - key.mv_data = &list[i].listid; - key.mv_size = sizeof(list[i].listid); - data.mv_data = &fdata; - data.mv_size = sizeof(fdata); - if (res = mdb_del(tx, db->file_by_list, &key, &data)) + if (res = mdb_del(tx, db->list_by_file, &key, NULL)) goto fail; + + printf("list entries: %zd\n", size); + + for (int i=0;iid + }; + printf("delete file %d from list %d @ %d\n", fdata.fileid, list[i].listid, fdata.seq); + key.mv_data = &list[i].listid; + key.mv_size = sizeof(list[i].listid); + data.mv_data = &fdata; + data.mv_size = sizeof(fdata); + if (res = mdb_del(tx, db->file_by_list, &key, &data)) + goto fail; + } + } else if (res == MDB_NOTFOUND) { + res = 0; } free(list); } @@ -1013,7 +1018,7 @@ void dbshuffle_init(dbindex *db) { // create shuffled playlist // TODO: start from an existing playlist? -void dbshuffle_init2(dbindex *db) { +void dbshuffle_init2(dbindex *db, dbid_t diskid) { dbtxn *tx; dbscan *scan; uint32_t fid; @@ -1026,7 +1031,7 @@ void dbshuffle_init2(dbindex *db) { // find all current fids mdb_txn_begin(db->env, NULL, 0, &tx); - scan = dbfile_scan_disk(tx, db, -1); + scan = dbfile_scan_disk(tx, db, diskid); while ((fid = dbfile_scan_next(scan)) != ~0) { if (count >= fids_size) { fids_size *= 2; @@ -1085,7 +1090,7 @@ void dbshuffle_init2(dbindex *db) { rvalue.seq = seq; rkey.mv_data = &fid; - printf(" %d->%d\n", seq, fid); + //printf(" %d->%d\n", seq, fid); if ((res = mdb_put(tx, db->file_by_list, &fkey, &fdata, MDB_NODUPDATA))) goto fail; diff --git a/disk-indexer.c b/disk-indexer.c index ba8c0e3..c9dcd08 100644 --- a/disk-indexer.c +++ b/disk-indexer.c @@ -702,7 +702,7 @@ int main(int argc, char **argv) { mkdir(dbdir, 0700); - if (1) { + if (0) { //suffix(dbdir); search_suffix(dbdir); return 0; diff --git a/disk-util.c b/disk-util.c index 765089b..d149a46 100644 --- a/disk-util.c +++ b/disk-util.c @@ -38,7 +38,7 @@ #include "dbindex.h" -void dbshuffle_init2(dbindex *db); +void dbshuffle_init2(dbindex *db, dbid_t diskid); int dbdisk_del_id(dbtxn *txn, dbindex *db, int diskid); void dbindex_validate(dbindex *db); @@ -59,6 +59,7 @@ int main(int argc, char **argv) { } mkdir(dbdir, 0700); + srandom(time(NULL)); dbindex *db = dbindex_open(dbdir); @@ -72,7 +73,9 @@ int main(int argc, char **argv) { } else if (strcmp(cmd, "-d") == 0) { diskid = atoi(argv[++i]); } else if (strcmp(cmd, "--shuffle") == 0) { - dbshuffle_init2(db); + int did = atoi(argv[++i]); + + dbshuffle_init2(db, did); } else if (strcmp(cmd, "--file-dump") == 0) { // dump file info // dump lists it's in