tmus

TUI Music Player
git clone https://git.sinitax.com/sinitax/tmus
Log | Files | Refs | Submodules | LICENSE | sfeed.txt

commit b44f4cb64ff6dbb05345c2cb297c3b7d84a11d24
parent e7b876506cbb2a0278e0ad40ec9cfe8e936482ca
Author: Louis Burda <quent.burda@gmail.com>
Date:   Sat,  5 Mar 2022 16:03:56 +0100

Check destination path in copy and move

Diffstat:
Msrc/cmd.c | 19++++++++++++++++---
Msrc/data.c | 4++++
2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/src/cmd.c b/src/cmd.c @@ -62,10 +62,17 @@ cmd_move(const char *name) newpath = aprintf("%s/%s", tag->fpath, track->name); OOM_CHECK(newpath); + + if (path_exists(newpath)) { + free(newpath); + CMD_ERROR("File already exists"); + } + if (!dup_file(track->fpath, newpath)) { free(newpath); CMD_ERROR("Failed to move track"); } + free(newpath); new = track_add(tag, track->name); @@ -92,7 +99,7 @@ cmd_copy(const char *name) char *newpath; tag = tag_find(name); - if (!tag) return 0; + if (!tag) CMD_ERROR("Tag not found"); link = list_at(tracks_vis, track_nav.sel); if (!link) CMD_ERROR("No track selected"); @@ -100,9 +107,15 @@ cmd_copy(const char *name) newpath = aprintf("%s/%s", tag->fpath, track->name); OOM_CHECK(newpath); + + if (path_exists(newpath)) { + free(newpath); + CMD_ERROR("File already exists"); + } + if (!dup_file(track->fpath, newpath)) { free(newpath); - ERROR("Failed to copy track"); + CMD_ERROR("Failed to copy track"); } free(newpath); @@ -112,7 +125,7 @@ cmd_copy(const char *name) CMD_ERROR("Failed to copy track"); } - return 1; + return true; } bool diff --git a/src/data.c b/src/data.c @@ -473,6 +473,10 @@ tag_rename(struct tag *tag, const char *name) free(tag->fpath); tag->fpath = newpath; + free(tag->name); + tag->name = strdup(name); + OOM_CHECK(tag->name); + for (LIST_ITER(&tag->tracks, link)) { track = UPCAST(link, struct track, link_tt); free(track->fpath);