gboolean cli_current (cli_context_t *ctx, command_t *cmd) { status_entry_t *status; const gchar *format; gint refresh; if (!command_flag_int_get (cmd, "refresh", &refresh)) { refresh = 0; } if (!command_flag_string_get (cmd, "format", &format)) { configuration_t *config = cli_context_config (ctx); format = configuration_get_string (config, "STATUS_FORMAT"); } status = currently_playing_init (ctx, format, refresh); if (refresh > 0) { cli_context_status_mode (ctx, status); } else { status_refresh (status, TRUE, TRUE); status_free (status); } return refresh != 0; /* need I/O if we are refreshing */ }
void env_close(struct env *e) { cache_free(e->cache); status_free(e->status); txnmgr_free(e->txnmgr); xfree(e->dir); xfree(e); }
/* * Free allocated items initialized by dpv() */ void dpv_free(void) { dialogrc_free(); dprompt_free(); dialog_maxsize_free(); if (aprompt != NULL) { free(aprompt); aprompt = NULL; } if (pprompt != NULL) { free(pprompt); pprompt = NULL; } status_free(); }
void readline_status_mode_exit (void) { Keymap active; g_assert (cli_context_in_status (readline_cli_ctx, CLI_ACTION_STATUS_REFRESH)); active = rl_get_keymap (); rl_set_keymap (rl_get_keymap_by_name (readline_keymap)); rl_discard_keymap (active); rl_callback_handler_remove (); g_free (readline_keymap); status_free (cli_context_status_entry (readline_cli_ctx)); // TODO: handle via cli_context_free or somesuch? cli_context_status_mode_exit (readline_cli_ctx); }
CTEST(cursor, empty) { int ret; struct options *opts; struct status *status; struct cache *cache; struct tree *tree; /* create */ opts = options_new(); status = status_new(); cache = dbcache_new(opts); tree = tree_new(DBPATH0, opts, status, cache, 1); /* cursor */ struct cursor *cur; cur = cursor_new(tree); /* first */ tree_cursor_first(cur); ret = tree_cursor_valid(cur); ASSERT_EQUAL(0, ret); /* last */ tree_cursor_last(cur); ret = tree_cursor_valid(cur); ASSERT_EQUAL(0, ret); /* next */ tree_cursor_next(cur); ret = tree_cursor_valid(cur); ASSERT_EQUAL(0, ret); cursor_free(cur); /* free */ dbcache_free(cache); tree_free(tree); options_free(opts); status_free(status); xcheck_all_free(); }
void status_mode (cli_infos_t *infos, gchar *format, gint refresh) { status_entry_t *status; status = status_init (format, refresh); if (refresh > 0) { g_printf (_("\n" " (n) next song\n" " (p) previous song\n" " (t) toggle playback\n" " (ENTER) exit status mode\n\n")); cli_infos_status_mode (infos, status); } else { status_update_all (infos, status); status_print_entry (status); status_free (status); cli_infos_loop_resume (infos); } }
/* * Close the status file and free any resource associated with it. * It is OK to pass NULL for errmsg only if the status file was * opened read-only. If it wasn't opened read-only, status_close() * can produce an error and errmsg is not allowed to be NULL. If * there was no errors, errmsg is set to NULL. */ void status_close(struct status *st, char **errmsg) { struct statusrec *sr; char *line, *name; int error, type; if (st->wr != NULL) { if (st->dirty) { if (st->current != NULL) { error = status_wr(st, st->current); if (error) { *errmsg = status_errmsg(st); goto bad; } st->current = NULL; } /* Copy the rest of the file. */ while ((sr = status_rdraw(st, &line)) != NULL) { error = status_wrraw(st, sr, line); if (error) { *errmsg = status_errmsg(st); goto bad; } } if (st->error) { *errmsg = status_errmsg(st); goto bad; } /* Close off all the open directories. */ pathcomp_finish(st->pc); while (pathcomp_get(st->pc, &type, &name)) { assert(type == PC_DIRUP); error = proto_printf(st->wr, "U %s %f\n", name, fattr_bogus); if (error) { st->error = STATUS_ERR_WRITE; st->suberror = errno; *errmsg = status_errmsg(st); goto bad; } } /* Rename tempfile. */ error = rename(st->tempfile, st->path); if (error) { st->error = STATUS_ERR_RENAME; st->suberror = errno; *errmsg = status_errmsg(st); goto bad; } } else { /* Just discard the tempfile. */ unlink(st->tempfile); } *errmsg = NULL; } status_free(st); return; bad: status_free(st); }
/* * Open the status file. If scantime is not -1, the file is opened * for updating, otherwise, it is opened read-only. If the status file * couldn't be opened, NULL is returned and errmsg is set to the error * message. */ struct status * status_open(struct coll *coll, time_t scantime, char **errmsg) { struct status *st; struct stream *file; struct fattr *fa; char *destpath, *path; int error, rv; path = coll_statuspath(coll); file = stream_open_file(path, O_RDONLY); if (file == NULL) { if (errno != ENOENT) { xasprintf(errmsg, "Could not open \"%s\": %s\n", path, strerror(errno)); free(path); return (NULL); } st = status_fromnull(path); } else { st = status_fromrd(path, file); if (st == NULL) { xasprintf(errmsg, "Error in \"%s\": Bad header line", path); free(path); return (NULL); } } if (scantime != -1) { /* Open for writing too. */ xasprintf(&destpath, "%s/%s/%s/", coll->co_base, coll->co_colldir, coll->co_name); st->tempfile = tempname(destpath); if (mkdirhier(destpath, coll->co_umask) != 0) { xasprintf(errmsg, "Cannot create directories leading " "to \"%s\": %s", destpath, strerror(errno)); free(destpath); status_free(st); return (NULL); } free(destpath); st->wr = stream_open_file(st->tempfile, O_CREAT | O_TRUNC | O_WRONLY, 0644); if (st->wr == NULL) { xasprintf(errmsg, "Cannot create \"%s\": %s", st->tempfile, strerror(errno)); status_free(st); return (NULL); } fa = fattr_new(FT_FILE, -1); fattr_mergedefault(fa); fattr_umask(fa, coll->co_umask); rv = fattr_install(fa, st->tempfile, NULL); fattr_free(fa); if (rv == -1) { xasprintf(errmsg, "Cannot set attributes for \"%s\": %s", st->tempfile, strerror(errno)); status_free(st); return (NULL); } if (scantime != st->scantime) st->dirty = 1; error = proto_printf(st->wr, "F %d %t\n", STATUS_VERSION, scantime); if (error) { st->error = STATUS_ERR_WRITE; st->suberror = errno; *errmsg = status_errmsg(st); status_free(st); return (NULL); } } return (st); }
CTEST(block_test, block_get) { struct status *status = status_new(); struct block *b = block_new(status); uint32_t height = 0; uint32_t skeleton_size = 0; uint64_t nid0 = 0; DISKOFF off0 = block_alloc_off(b, nid0, 513, skeleton_size, height); /* {1024 to 2048} */ ASSERT_EQUAL(1024, off0); uint64_t nid1 = 1; off0 = block_alloc_off(b, nid1, 513, skeleton_size, height); /* {2048 to 3072} */ ASSERT_EQUAL(2048, off0); uint64_t nid2 = 2; off0 = block_alloc_off(b, nid2, 512, skeleton_size, height); /* {3072 to 3584} */ ASSERT_EQUAL(3072, off0); uint64_t nid3 = 3; off0 = block_alloc_off(b, nid3, 511, skeleton_size, height); /* {3584 to 4096} */ ASSERT_EQUAL(3584, off0); /* realloc nid1 */ nid1 = 1; off0 = block_alloc_off(b, nid1, 513, skeleton_size, height); /* * {4096 to 5120} is used * {2048 to 3072} is unused */ ASSERT_EQUAL(4096, off0); /* realloc nid2 */ nid2 = 2; off0 = block_alloc_off(b, nid2, 512, skeleton_size, height); /* * {5120 to 5632} used * {3072 to 3584} is unused */ ASSERT_EQUAL(5120, off0); block_shrink(b); uint64_t nid4 = 4; off0 = block_alloc_off(b, nid4, 511, skeleton_size, height); ASSERT_EQUAL(2048, off0); uint64_t nid5 = 5; off0 = block_alloc_off(b, nid5, 511, skeleton_size, height); ASSERT_EQUAL(2560, off0); block_free(b); status_free(status); }