+ }
+ afs_event(AUDIO_FILE_REMOVE, &crd->pb, row);
+ ret = osl_del_row(audio_file_table, row);
+ if (ret < 0)
+ para_printf(&crd->pb, "%s: %s\n", name, para_strerror(-ret));
+ else
+ crd->num_removed++;
+ return ret;
+}
+
+static void com_rm_callback(int fd, const struct osl_object *query)
+{
+ struct com_rm_action_data crd = {.flags = *(uint32_t *)query->data,
+ .pb = {
+ .max_size = SHMMAX,
+ .private_data = &fd,
+ .max_size_handler = pass_buffer_as_shm
+ }
+ };
+ int ret;
+ struct pattern_match_data pmd = {
+ .table = audio_file_table,
+ .loop_col_num = AFTCOL_HASH,
+ .match_col_num = AFTCOL_PATH,
+ .patterns = {.data = (char *)query->data + sizeof(uint32_t),
+ .size = query->size - sizeof(uint32_t)},
+ .data = &crd,
+ .action = remove_audio_file
+ };
+ if (crd.flags & RM_FLAG_FNM_PATHNAME)
+ pmd.fnmatch_flags |= FNM_PATHNAME;
+ ret = for_each_matching_row(&pmd);
+ if (ret < 0) {
+ para_printf(&crd.pb, "%s\n", para_strerror(-ret));
+ return;
+ }
+ if (!crd.num_removed && !(crd.flags & RM_FLAG_FORCE))
+ ret = para_printf(&crd.pb, "no matches -- nothing removed\n");
+ else {
+ if (crd.flags & RM_FLAG_VERBOSE)
+ ret = para_printf(&crd.pb, "removed %u files\n", crd.num_removed);
+ }
+ if (ret >= 0 && crd.pb.offset)
+ pass_buffer_as_shm(crd.pb.buf, crd.pb.offset, &fd);
+ free(crd.pb.buf);
+}
+
+/* TODO options: -r (recursive) */
+int com_rm(int fd, int argc, char * const * const argv)
+{
+ uint32_t flags = 0;
+ struct osl_object query = {.data = &flags, .size = sizeof(flags)};
+ int i, ret;
+
+ for (i = 1; i < argc; i++) {
+ const char *arg = argv[i];
+ if (arg[0] != '-')
+ break;
+ if (!strcmp(arg, "--")) {
+ i++;
+ break;
+ }
+ if (!strcmp(arg, "-f")) {
+ flags |= RM_FLAG_FORCE;
+ continue;
+ }
+ if (!strcmp(arg, "-p")) {
+ flags |= RM_FLAG_FNM_PATHNAME;
+ continue;
+ }
+ if (!strcmp(arg, "-v")) {
+ flags |= RM_FLAG_VERBOSE;
+ continue;
+ }
+ break;
+ }
+ if (i >= argc)
+ return -E_AFT_SYNTAX;
+ ret = send_option_arg_callback_request(&query, argc - i, argv + i,
+ com_rm_callback, send_result, &fd);
+ if (ret < 0)
+ send_va_buffer(fd, "%s\n", para_strerror(-ret));
+ return ret;
+}
+
+/**
+ * Flags used by the cpsi command.
+ *
+ * \sa com_cpsi().
+ */
+enum cpsi_flags {
+ /** Whether the lyrics id should be copied. */
+ CPSI_FLAG_COPY_LYRICS_ID = 1,
+ /** Whether the image id should be copied. */
+ CPSI_FLAG_COPY_IMAGE_ID = 2,
+ /** Whether the lastplayed time should be copied. */
+ CPSI_FLAG_COPY_LASTPLAYED = 4,
+ /** Whether the numplayed count should be copied. */
+ CPSI_FLAG_COPY_NUMPLAYED = 8,
+ /** Whether the attributes should be copied. */
+ CPSI_FLAG_COPY_ATTRIBUTES = 16,
+ /** Activates verbose mode. */
+ CPSI_FLAG_VERBOSE = 32,
+};
+
+/** Data passed to the action handler of com_cpsi(). */
+struct cpsi_action_data {
+ /** command line flags (see \ref cpsi_flags). */
+ unsigned flags;
+ /** Number of audio files changed. */
+ unsigned num_copied;
+ /** Message buffer. */
+ struct para_buffer pb;
+ /** Values are copied from here. */
+ struct afs_info source_afsi;
+};
+
+static int copy_selector_info(__a_unused struct osl_table *table,
+ struct osl_row *row, const char *name, void *data)
+{
+ struct cpsi_action_data *cad = data;
+ struct osl_object target_afsi_obj;
+ int ret;
+ struct afs_info old_afsi, target_afsi;
+ struct afsi_change_event_data aced;
+
+ ret = get_afsi_object_of_row(row, &target_afsi_obj);
+ if (ret < 0)
+ return ret;
+ load_afsi(&target_afsi, &target_afsi_obj);
+ old_afsi = target_afsi;
+ if (cad->flags & CPSI_FLAG_COPY_LYRICS_ID)
+ target_afsi.lyrics_id = cad->source_afsi.lyrics_id;
+ if (cad->flags & CPSI_FLAG_COPY_IMAGE_ID)
+ target_afsi.image_id = cad->source_afsi.image_id;
+ if (cad->flags & CPSI_FLAG_COPY_LASTPLAYED)
+ target_afsi.last_played = cad->source_afsi.last_played;
+ if (cad->flags & CPSI_FLAG_COPY_NUMPLAYED)
+ target_afsi.num_played = cad->source_afsi.num_played;
+ if (cad->flags & CPSI_FLAG_COPY_ATTRIBUTES)
+ target_afsi.attributes = cad->source_afsi.attributes;
+ save_afsi(&target_afsi, &target_afsi_obj); /* in-place update */
+ cad->num_copied++;
+ if (cad->flags & CPSI_FLAG_VERBOSE) {
+ ret = para_printf(&cad->pb, "copied afsi to %s\n", name);