chiark
/
gitweb
/
~mdw
/
disorder
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
document new choose screen properly
[disorder]
/
lib
/
trackdb.c
diff --git
a/lib/trackdb.c
b/lib/trackdb.c
index 6a93fbaba33562676ea7fd0f828ca64855d2dd10..54016bae0c8bcaf2fff04784ce00b3c3068abaef 100644
(file)
--- a/
lib/trackdb.c
+++ b/
lib/trackdb.c
@@
-162,6
+162,16
@@
static int compare(DB attribute((unused)) *db_,
return compare_path_raw(a->data, a->size, b->data, b->size);
}
return compare_path_raw(a->data, a->size, b->data, b->size);
}
+/** @brief Test whether the track database can be read
+ * @return 1 if it can, 0 if it cannot
+ */
+int trackdb_readable(void) {
+ char *usersdb;
+
+ byte_xasprintf(&usersdb, "%s/users.db", config->home);
+ return access(usersdb, R_OK) == 0;
+}
+
/** @brief Open database environment
* @param flags Flags word
*
/** @brief Open database environment
* @param flags Flags word
*
@@
-1004,7
+1014,8
@@
int trackdb_notice_tid(const char *track,
int err, n;
struct kvp *t, *a, *p;
int t_changed, ret;
int err, n;
struct kvp *t, *a, *p;
int t_changed, ret;
- char *alias, **w;
+ char *alias, **w, *noticed;
+ time_t now;
/* notice whether the tracks.db entry changes */
t_changed = 0;
/* notice whether the tracks.db entry changes */
t_changed = 0;
@@
-1015,6
+1026,12
@@
int trackdb_notice_tid(const char *track,
/* this is a real track */
t_changed += kvp_set(&t, "_alias_for", 0);
t_changed += kvp_set(&t, "_path", path);
/* this is a real track */
t_changed += kvp_set(&t, "_alias_for", 0);
t_changed += kvp_set(&t, "_path", path);
+ time(&now);
+ if(ret == DB_NOTFOUND) {
+ /* It's a new track; record the time */
+ byte_xasprintf(¬iced, "%lld", (long long)now);
+ t_changed += kvp_set(&t, "_noticed", noticed);
+ }
/* if we have an alias record it in the database */
if((err = compute_alias(&alias, track, p, tid))) return err;
if(alias) {
/* if we have an alias record it in the database */
if((err = compute_alias(&alias, track, p, tid))) return err;
if(alias) {
@@
-1039,10
+1056,8
@@
int trackdb_notice_tid(const char *track,
return err;
if(ret == DB_NOTFOUND) {
uint32_t timestamp[2];
return err;
if(ret == DB_NOTFOUND) {
uint32_t timestamp[2];
- time_t now;
DBT key, data;
DBT key, data;
- time(&now);
timestamp[0] = htonl((uint64_t)now >> 32);
timestamp[1] = htonl((uint32_t)now);
memset(&key, 0, sizeof key);
timestamp[0] = htonl((uint64_t)now >> 32);
timestamp[1] = htonl((uint32_t)now);
memset(&key, 0, sizeof key);
@@
-2630,10
+2645,13
@@
int trackdb_edituserinfo(const char *user,
return -1;
}
} else if(!strcmp(key, "email")) {
return -1;
}
} else if(!strcmp(key, "email")) {
- if(!strchr(value, '@')) {
- error(0, "invalid email address '%s' for user '%s'", user, value);
- return -1;
- }
+ if(*value) {
+ if(!strchr(value, '@')) {
+ error(0, "invalid email address '%s' for user '%s'", user, value);
+ return -1;
+ }
+ } else
+ value = 0; /* no email -> remove key */
} else if(!strcmp(key, "created")) {
error(0, "cannot change creation date for user '%s'", user);
return -1;
} else if(!strcmp(key, "created")) {
error(0, "cannot change creation date for user '%s'", user);
return -1;