diff options
author | Aidan MacDonald <amachronic@protonmail.com> | 2022-03-31 20:14:19 +0100 |
---|---|---|
committer | Aidan MacDonald <amachronic@protonmail.com> | 2022-04-01 11:40:02 -0400 |
commit | 5ffe520de4c70cfabc67a329cdb77d3d997bd45a (patch) | |
tree | 509537d1b39d732091fc8b2aa2464c0fd10108c2 /apps/playlist.c | |
parent | 4f05a9d066337a883d8d82b531ff8db5c989e5b9 (diff) | |
download | rockbox-5ffe520de4c70cfabc67a329cdb77d3d997bd45a.tar.gz rockbox-5ffe520de4c70cfabc67a329cdb77d3d997bd45a.zip |
playlist: use path_strip_last_volume, clarify path conventions
The comment regarding Windows paths was fairly confusing as to
its intent. What the code is trying to do is replace the drive
letter with the volume containing the playlist, which appears
reasonable. The middle of the comment was devoted to explaining
why the code below was potentially incorrect which only served
to add to the confusion.
AFAICT the last volume specifier in a path will cause search to
start from the root of that volume, so any incorrect result can
be avoided by using the new function path_strip_last_volume().
Finally, add a comment at the top of the function that explains
what it does.
Change-Id: If4e4938801f2f81eb52f5d32b5461872995e5e83
Diffstat (limited to 'apps/playlist.c')
-rw-r--r-- | apps/playlist.c | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/apps/playlist.c b/apps/playlist.c index 88a6869895..32b8383442 100644 --- a/apps/playlist.c +++ b/apps/playlist.c | |||
@@ -1741,6 +1741,20 @@ static int check_subdir_for_music(char *dir, const char *subdir, bool recurse) | |||
1741 | 1741 | ||
1742 | /* | 1742 | /* |
1743 | * Returns absolute path of track | 1743 | * Returns absolute path of track |
1744 | * | ||
1745 | * dest: output buffer | ||
1746 | * src: the file name from the playlist | ||
1747 | * dir: the absolute path to the directory where the playlist resides | ||
1748 | * | ||
1749 | * The type of path in "src" determines what will be written to "dest": | ||
1750 | * | ||
1751 | * 1. UNIX-style absolute paths (/foo/bar) remain unaltered | ||
1752 | * 2. Windows-style absolute paths (C:/foo/bar) will be converted into an | ||
1753 | * absolute path by replacing the drive letter with the volume that the | ||
1754 | * *playlist* resides on, ie. the volume in "dir" | ||
1755 | * 3. Relative paths are converted to absolute paths by prepending "dir". | ||
1756 | * This also applies to Windows-style relative paths "C:foo/bar" where | ||
1757 | * the drive letter is accepted but ignored. | ||
1744 | */ | 1758 | */ |
1745 | static ssize_t format_track_path(char *dest, char *src, int buf_length, | 1759 | static ssize_t format_track_path(char *dest, char *src, int buf_length, |
1746 | const char *dir) | 1760 | const char *dir) |
@@ -1770,27 +1784,13 @@ static ssize_t format_track_path(char *dest, char *src, int buf_length, | |||
1770 | /* Replace backslashes with forward slashes */ | 1784 | /* Replace backslashes with forward slashes */ |
1771 | path_correct_separators(src, src); | 1785 | path_correct_separators(src, src); |
1772 | 1786 | ||
1773 | /* Drive letters have no meaning here; handle DOS style drive letter | 1787 | /* Handle Windows-style absolute paths */ |
1774 | * and parse greedily so that: | ||
1775 | * | ||
1776 | * 1) "c:/foo" is fully qualified, use directory volume only | ||
1777 | * 2) "c:foo" is relative to current directory on C, use directory path | ||
1778 | * | ||
1779 | * Assume any volume on the beginning of the directory path is actually | ||
1780 | * the volume on which it resides. This may not be the case if the dir | ||
1781 | * param contains a path such as "/<1>/foo/../../<0>/bar", which refers | ||
1782 | * to "/<0>/bar" (aka "/bar" at this time). *fingers crossed* | ||
1783 | * | ||
1784 | * If any stripped drive spec was absolute, prepend the playlist | ||
1785 | * directory's volume spec, or root if none. Absolute UNIX-style paths | ||
1786 | * remain unaltered. | ||
1787 | */ | ||
1788 | if (path_strip_drive(src, (const char **)&src, true) >= 0 && | 1788 | if (path_strip_drive(src, (const char **)&src, true) >= 0 && |
1789 | src[-1] == PATH_SEPCH) | 1789 | src[-1] == PATH_SEPCH) |
1790 | { | 1790 | { |
1791 | #ifdef HAVE_MULTIVOLUME | 1791 | #ifdef HAVE_MULTIVOLUME |
1792 | const char *p; | 1792 | const char *p; |
1793 | path_strip_volume(dir, &p, false); | 1793 | path_strip_last_volume(dir, &p, false); |
1794 | dir = strmemdupa(dir, p - dir); /* empty if no volspec on dir */ | 1794 | dir = strmemdupa(dir, p - dir); /* empty if no volspec on dir */ |
1795 | #else | 1795 | #else |
1796 | dir = ""; /* only volume is root */ | 1796 | dir = ""; /* only volume is root */ |