@@ -20,7 +20,7 @@ pub struct Config {
2020 /// Folder containing audio files (can be anywhere).
2121 ///
2222 /// If relative, it is resolved relative to the executable's directory.
23- #[ serde( default ) ]
23+ #[ serde( default , alias = "SONG_FOLDER" ) ]
2424 pub songs_dir : PathBuf ,
2525
2626 /// Audio files discovered from `songs_dir`
@@ -47,17 +47,28 @@ impl Config {
4747 // Resolve songs_dir:
4848 // - if missing/empty => default to <exe_dir>/songs
4949 // - if relative => resolve relative to exe_dir
50- if config. songs_dir . as_os_str ( ) . is_empty ( ) {
51- config. songs_dir = exe_dir. join ( "songs" ) ;
52- } else if config. songs_dir . is_relative ( ) {
53- config. songs_dir = exe_dir. join ( & config. songs_dir ) ;
54- }
50+ // - always produce an absolute path
51+ config. songs_dir = Self :: resolve_songs_dir ( & exe_dir, & config. songs_dir ) ;
5552
5653 config. songs = Self :: load_songs_from ( & config. songs_dir ) ;
5754
5855 Some ( config)
5956 }
6057
58+ fn resolve_songs_dir ( config_dir : & Path , configured : & Path ) -> PathBuf {
59+ let resolved = if configured. as_os_str ( ) . is_empty ( ) {
60+ config_dir. join ( "songs" )
61+ } else if configured. is_relative ( ) {
62+ config_dir. join ( configured)
63+ } else {
64+ configured. to_path_buf ( )
65+ } ;
66+
67+ // Canonicalize when possible for a normalized full path. If the folder
68+ // doesn't exist yet, keep the resolved absolute path as-is.
69+ fs:: canonicalize ( & resolved) . unwrap_or ( resolved)
70+ }
71+
6172 /// Scans a folder for supported audio files (.mp3, .wav, .ogg, .flac)
6273 fn load_songs_from ( dir : & Path ) -> Vec < PathBuf > {
6374 let entries = match fs:: read_dir ( dir) {
@@ -96,4 +107,4 @@ impl Config {
96107 eprintln ! ( "Failed to open songs folder: {e}" ) ;
97108 }
98109 }
99- }
110+ }
0 commit comments