return 0;
}
-static int list_keys(const char *dbpath, char ***keys, unsigned int *klen)
+static int list_keys(const char *dbpath, char ***keys, unsigned int *klen,
+ bool readonly)
{
GDBM_FILE db;
GList *list;
return -1;
}
- db = open_gdbm(dbpath, true);
+ db = open_gdbm(dbpath, readonly);
if (!db)
return -1;
return ret;
}
-static int list_keys(const char *dbpath, char ***keys, unsigned int *klen)
+static int list_keys(const char *dbpath, char ***keys, unsigned int *klen,
+ bool readonly)
{
sqlite3 *db;
GList *list;
return -1;
}
- db = open_sqlite3(dbpath, true);
+ db = open_sqlite3(dbpath, readonly);
if (!db)
return -1;
if (r == -1)
return -1;
- r = direct_list(layer, &keys, NULL);
+ r = direct_list(layer, &keys, NULL, true);
c_exit();
return 0;
}
+int c_direct_remove_garbage(const struct buxton_layer *layer,
+ UNUSED const char *key, UNUSED const char *value,
+ UNUSED const char *rpriv, UNUSED const char *wpriv)
+{
+ struct buxton_layer *normal_layer;
+ struct buxton_layer *base_layer;
+ struct buxton_value val;
+ char **keys;
+ unsigned int len;
+ int r;
+ int i;
+ char err_buf[BUFFER_SIZE];
+
+ if (!layer) {
+ errno = EINVAL;
+ strerror_r(errno, err_buf, sizeof(err_buf));
+ bxt_err("Remove garbage data : Layer '%s' : %s",
+ layer ? buxton_layer_get_name(layer) : "",
+ err_buf);
+ return -1;
+ }
+
+ r = c_init();
+ if (r == -1)
+ return -1;
+
+ normal_layer = buxton_create_layer(layer->name);
+ buxton_layer_set_type(normal_layer, BUXTON_LAYER_NORMAL);
+ base_layer = buxton_create_layer(layer->name);
+ buxton_layer_set_type(base_layer, BUXTON_LAYER_BASE);
+
+ r = direct_list(normal_layer, &keys, &len, false);
+ if (r == -1) {
+ buxton_free_layer(normal_layer);
+ buxton_free_layer(base_layer);
+ return -1;
+ }
+
+ i = 0;
+ while (i < len) {
+ r = direct_get(base_layer, keys[i], &val);
+ if (r == -1 && errno == ENOENT) {
+ r = direct_unset(normal_layer, keys[i]);
+ if (r == -1) {
+ strerror_r(errno, err_buf, sizeof(err_buf));
+ bxt_err("Remove garbage data: Layer '%s' Key '%s': %s",
+ buxton_layer_get_name(normal_layer), keys[i],
+ err_buf);
+ }
+ }
+ value_free(&val);
+ i++;
+ }
+
+ c_exit();
+ buxton_free_layer(normal_layer);
+ buxton_free_layer(base_layer);
+
+ return 0;
+}
int c_direct_create_bool(const struct buxton_layer *layer,
const char *key, const char *value,
const char *rpriv, const char *wpriv);
+int c_direct_remove_garbage(UNUSED const struct buxton_layer *layer,
+ UNUSED const char *key, UNUSED const char *value,
+ UNUSED const char *rpriv, UNUSED const char *wpriv);
.func = c_disable_security,
.dfunc = NULL,
},
+ {
+ .name = "remove-garbage-data",
+ .summary = "Remove garbage data",
+ .nargs = 1,
+ .usage = "LAYER",
+ .func = c_direct_remove_garbage,
+ .dfunc = c_direct_remove_garbage,
+ },
};
static const struct command *find_comm(const char *name)
printf(" Command:\n");
for (i = 0; i < sizeof(commands) / sizeof(commands[0]); i++)
- printf("%16s - %s\n", commands[i].name, commands[i].summary);
+ printf("%20s - %s\n", commands[i].name, commands[i].summary);
printf("\n");
printf(" Example:\n");
int c_disable_security(UNUSED const struct buxton_layer *layer,
UNUSED const char *key, UNUSED const char *value,
UNUSED const char *rpriv, UNUSED const char *wpriv);
+int c_remove_trash_data(UNUSED const struct buxton_layer *layer,
+ UNUSED const char *key, UNUSED const char *value,
+ UNUSED const char *rpriv, UNUSED const char *wpriv);
const char *key, void **data, int *dlen, bool readonly);
typedef int (*backend_unset_value)(const char *dbpath, const char *key);
typedef int (*backend_list_keys)(const char *dbpath,
- char ***keys, unsigned int *klen);
+ char ***keys, unsigned int *klen, bool readonly);
struct backend {
const char *name;
}
int direct_list(const struct buxton_layer *layer,
- char ***names, unsigned int *len)
+ char ***names, unsigned int *len, bool is_base)
{
int r;
const struct layer *ly;
return -1;
}
- r = get_path(layer->uid, BUXTON_LAYER_BASE, ly, path, sizeof(path));
+ r = get_path(layer->uid, is_base ?
+ BUXTON_LAYER_BASE : BUXTON_LAYER_NORMAL,
+ ly, path, sizeof(path));
if (r == -1)
return -1;
- r = backend->list_keys(path, names, &_len);
+ r = backend->list_keys(path, names, &_len, is_base);
if (r == -1) {
bxt_err("List: list_keys: %d", errno);
return -1;
int direct_unset(const struct buxton_layer *layer, const char *key);
int direct_list(const struct buxton_layer *layer,
- char ***names, unsigned int *len);
+ char ***names, unsigned int *len, bool is_base);
int direct_get_priv(const struct buxton_layer *layer,
const char *key, enum buxton_priv_type type, char **priv);
assert(rqst);
assert(resp);
- r = direct_list(rqst->layer, &resp->names, &resp->nmlen);
+ r = direct_list(rqst->layer, &resp->names, &resp->nmlen, true);
resp->res = (r == -1) ? errno : 0;
}