Skip to content

Commit 452d7de

Browse files
committed
ADD --force flag to cmd_save
Allow to replace an existing playlist, calling mpd_send_save_queue with the MPD_QUEUE_SAVE_MODE_REPLACE flag.
1 parent ec10401 commit 452d7de

4 files changed

Lines changed: 25 additions & 2 deletions

File tree

doc/index.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ Options
8484

8585
Wait for operation to finish (e.g. database update).
8686

87+
.. option:: -F, --force
88+
89+
Force certain operations (e.g. overwriting playlist while saving).
90+
8791
.. option:: --range=[START]:[END]
8892

8993
Operate on a range (e.g. when loading a playlist). START is the
@@ -250,7 +254,8 @@ Playlist Commands
250254

251255
:command:`rm <file>` - Deletes a specific playlist.
252256

253-
:command:`save <file>` - Saves playlist as <file>.
257+
:command:`save [--force] <file>` - Saves playlist as <file>. With
258+
:option:`--force`, overwrites the playlist if it already exists.
254259

255260
:command:`addplaylist <playlist> <file>` - Adds a song from the music database to the
256261
playlist. The playlist will be created if it does not exist.

src/command.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ SIMPLE_CMD(cmd_prev, mpd_run_previous, 1)
2828
SIMPLE_CMD(cmd_stop, mpd_run_stop, 1)
2929
SIMPLE_CMD(cmd_clearerror, mpd_run_clearerror, 1)
3030

31-
SIMPLE_ONEARG_CMD(cmd_save, mpd_run_save, 0)
3231
SIMPLE_ONEARG_CMD(cmd_rm, mpd_run_rm, 0)
3332

3433
/**
@@ -1376,3 +1375,16 @@ cmd_partitiondelete(int argc, char **argv, struct mpd_connection *conn) {
13761375
}
13771376
return 0;
13781377
}
1378+
1379+
int
1380+
cmd_save(gcc_unused int argc, char **argv, struct mpd_connection *conn)
1381+
{
1382+
if (options.force) {
1383+
if (!mpd_send_save_queue(conn, charset_to_utf8(argv[0]), MPD_QUEUE_SAVE_MODE_REPLACE))
1384+
printErrorAndExit(conn);
1385+
} else {
1386+
if (!mpd_run_save(conn, charset_to_utf8(argv[0])))
1387+
printErrorAndExit(conn);
1388+
}
1389+
return 0;
1390+
}

src/options.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ static const struct OptionDef option_table[] = {
4848
{ 'w', "wait", NULL, "Wait for operation to finish (e.g. database update)" },
4949
{ 'r', "range", "[<start>]:[<end>]", "Operate on a range (e.g. when loading a playlist)" },
5050
{ 'a', "partition", "<name>", "Operate on partition <name> instead" },
51+
{ 'F', "force", NULL, "Force some operations (like saving playlist)" },
5152
{ OPTION_WITH_PRIO, "with-prio", NULL, "Show only songs that have a non-zero priority" },
5253
};
5354

@@ -164,6 +165,10 @@ handle_option(int c, const char *arg)
164165
options.wait = true;
165166
break;
166167

168+
case 'F':
169+
options.force = true;
170+
break;
171+
167172
case 'r':
168173
ParseRange(&options.range, arg);
169174
break;

src/options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct Options {
2828

2929
int verbosity; // 0 for quiet, 1 for default, 2 for verbose
3030
bool wait;
31+
bool force;
3132

3233
bool custom_format;
3334

0 commit comments

Comments
 (0)