From e10c8bafdf86e10fa0b99e55fe299b370fbbb9ed Mon Sep 17 00:00:00 2001 From: sentriz Date: Fri, 12 Nov 2021 20:14:57 +0000 Subject: [PATCH] refactor: remove godirwalk dep --- go.mod | 1 - go.sum | 2 - .../testdata/test_get_album_list_alpha_artist | 18 +-- .../testdata/test_get_album_list_alpha_name | 18 +-- .../testdata/test_get_album_list_newest | 18 +-- .../testdata/test_get_album_list_random | 72 +++++------ .../test_get_album_list_two_alpha_artist | 12 +- .../test_get_album_list_two_alpha_name | 12 +- .../testdata/test_get_album_list_two_newest | 12 +- .../testdata/test_get_album_list_two_random | 56 ++++----- .../testdata/test_get_album_with_cover | 20 ++-- .../testdata/test_get_album_without_cover | 78 +----------- .../testdata/test_get_artist_id_one | 12 +- .../testdata/test_get_indexes_no_args | 4 +- .../test_get_indexes_with_music_folder_1 | 2 +- .../test_get_indexes_with_music_folder_2 | 2 +- .../test_get_music_directory_with_tracks | 22 ++-- .../test_get_music_directory_without_tracks | 56 ++------- .../testdata/test_search_three_q_alb | 12 +- .../testdata/test_search_three_q_tra | 54 ++++----- .../testdata/test_search_two_q_alb | 18 +-- .../testdata/test_search_two_q_art | 6 +- .../testdata/test_search_two_q_tra | 36 +++--- server/mockfs/mockfs.go | 2 +- server/scanner/scanner.go | 113 +++++++++--------- server/server.go | 2 +- 26 files changed, 275 insertions(+), 385 deletions(-) diff --git a/go.mod b/go.mod index 3453813a..e6775d2c 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,6 @@ require ( github.com/jinzhu/gorm v1.9.16 github.com/josephburnett/jd v0.0.0-20191228205456-aa1a7c66b42f github.com/json-iterator/go v1.1.12 // indirect - github.com/karrick/godirwalk v1.16.1 github.com/matryer/is v1.4.0 github.com/mewkiz/pkg v0.0.0-20211102230744-16a6ce8f1b77 // indirect github.com/mitchellh/copystructure v1.2.0 // indirect diff --git a/go.sum b/go.sum index aa074251..6250e178 100644 --- a/go.sum +++ b/go.sum @@ -213,8 +213,6 @@ github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHm github.com/jszwec/csvutil v1.5.1/go.mod h1:Rpu7Uu9giO9subDyMCIQfHVDuLrcaC36UA4YcJjGBkg= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= -github.com/karrick/godirwalk v1.16.1 h1:DynhcF+bztK8gooS0+NDJFrdNZjJ3gzVzC545UNA9iw= -github.com/karrick/godirwalk v1.16.1/go.mod h1:j4mkqPuvaLI8mp1DroR3P6ad7cyYd4c1qeJ3RV7ULlk= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= diff --git a/server/ctrlsubsonic/testdata/test_get_album_list_alpha_artist b/server/ctrlsubsonic/testdata/test_get_album_list_alpha_artist index 8d2cca61..72d9ee76 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_list_alpha_artist +++ b/server/ctrlsubsonic/testdata/test_get_album_list_alpha_artist @@ -6,39 +6,39 @@ "albumList": { "album": [ { - "id": "al-2", - "coverArt": "al-2", + "id": "al-3", + "coverArt": "al-3", "artist": "artist-0", "created": "2019-11-30T00:00:00Z", "title": "album-0", "album": "", - "parent": "al-1", + "parent": "al-2", "isDir": true, "name": "", "songCount": 3, "duration": 300 }, { - "id": "al-3", - "coverArt": "al-3", + "id": "al-4", + "coverArt": "al-4", "artist": "artist-0", "created": "2019-11-30T00:00:00Z", "title": "album-1", "album": "", - "parent": "al-1", + "parent": "al-2", "isDir": true, "name": "", "songCount": 3, "duration": 300 }, { - "id": "al-4", - "coverArt": "al-4", + "id": "al-5", + "coverArt": "al-5", "artist": "artist-0", "created": "2019-11-30T00:00:00Z", "title": "album-2", "album": "", - "parent": "al-1", + "parent": "al-2", "isDir": true, "name": "", "songCount": 3, diff --git a/server/ctrlsubsonic/testdata/test_get_album_list_alpha_name b/server/ctrlsubsonic/testdata/test_get_album_list_alpha_name index 4e04828d..41c90492 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_list_alpha_name +++ b/server/ctrlsubsonic/testdata/test_get_album_list_alpha_name @@ -6,13 +6,13 @@ "albumList": { "album": [ { - "id": "al-2", - "coverArt": "al-2", + "id": "al-3", + "coverArt": "al-3", "artist": "artist-0", "created": "2019-11-30T00:00:00Z", "title": "album-0", "album": "", - "parent": "al-1", + "parent": "al-2", "isDir": true, "name": "", "songCount": 3, @@ -45,13 +45,13 @@ "duration": 300 }, { - "id": "al-3", - "coverArt": "al-3", + "id": "al-4", + "coverArt": "al-4", "artist": "artist-0", "created": "2019-11-30T00:00:00Z", "title": "album-1", "album": "", - "parent": "al-1", + "parent": "al-2", "isDir": true, "name": "", "songCount": 3, @@ -84,13 +84,13 @@ "duration": 300 }, { - "id": "al-4", - "coverArt": "al-4", + "id": "al-5", + "coverArt": "al-5", "artist": "artist-0", "created": "2019-11-30T00:00:00Z", "title": "album-2", "album": "", - "parent": "al-1", + "parent": "al-2", "isDir": true, "name": "", "songCount": 3, diff --git a/server/ctrlsubsonic/testdata/test_get_album_list_newest b/server/ctrlsubsonic/testdata/test_get_album_list_newest index 8d2cca61..72d9ee76 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_list_newest +++ b/server/ctrlsubsonic/testdata/test_get_album_list_newest @@ -6,39 +6,39 @@ "albumList": { "album": [ { - "id": "al-2", - "coverArt": "al-2", + "id": "al-3", + "coverArt": "al-3", "artist": "artist-0", "created": "2019-11-30T00:00:00Z", "title": "album-0", "album": "", - "parent": "al-1", + "parent": "al-2", "isDir": true, "name": "", "songCount": 3, "duration": 300 }, { - "id": "al-3", - "coverArt": "al-3", + "id": "al-4", + "coverArt": "al-4", "artist": "artist-0", "created": "2019-11-30T00:00:00Z", "title": "album-1", "album": "", - "parent": "al-1", + "parent": "al-2", "isDir": true, "name": "", "songCount": 3, "duration": 300 }, { - "id": "al-4", - "coverArt": "al-4", + "id": "al-5", + "coverArt": "al-5", "artist": "artist-0", "created": "2019-11-30T00:00:00Z", "title": "album-2", "album": "", - "parent": "al-1", + "parent": "al-2", "isDir": true, "name": "", "songCount": 3, diff --git a/server/ctrlsubsonic/testdata/test_get_album_list_random b/server/ctrlsubsonic/testdata/test_get_album_list_random index 084698e7..4767066d 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_list_random +++ b/server/ctrlsubsonic/testdata/test_get_album_list_random @@ -6,11 +6,11 @@ "albumList": { "album": [ { - "id": "al-13", - "coverArt": "al-13", + "id": "al-12", + "coverArt": "al-12", "artist": "artist-2", "created": "2019-11-30T00:00:00Z", - "title": "album-2", + "title": "album-1", "album": "", "parent": "al-10", "isDir": true, @@ -19,50 +19,37 @@ "duration": 300 }, { - "id": "al-8", - "coverArt": "al-8", + "id": "al-7", + "coverArt": "al-7", "artist": "artist-1", "created": "2019-11-30T00:00:00Z", - "title": "album-1", - "album": "", - "parent": "al-6", - "isDir": true, - "name": "", - "songCount": 3, - "duration": 300 - }, - { - "id": "al-2", - "coverArt": "al-2", - "artist": "artist-0", - "created": "2019-11-30T00:00:00Z", "title": "album-0", "album": "", - "parent": "al-1", + "parent": "al-6", "isDir": true, "name": "", "songCount": 3, "duration": 300 }, { - "id": "al-3", - "coverArt": "al-3", + "id": "al-4", + "coverArt": "al-4", "artist": "artist-0", "created": "2019-11-30T00:00:00Z", "title": "album-1", "album": "", - "parent": "al-1", + "parent": "al-2", "isDir": true, "name": "", "songCount": 3, "duration": 300 }, { - "id": "al-11", - "coverArt": "al-11", + "id": "al-13", + "coverArt": "al-13", "artist": "artist-2", "created": "2019-11-30T00:00:00Z", - "title": "album-0", + "title": "album-2", "album": "", "parent": "al-10", "isDir": true, @@ -84,39 +71,52 @@ "duration": 300 }, { - "id": "al-7", - "coverArt": "al-7", - "artist": "artist-1", + "id": "al-11", + "coverArt": "al-11", + "artist": "artist-2", "created": "2019-11-30T00:00:00Z", "title": "album-0", "album": "", - "parent": "al-6", + "parent": "al-10", "isDir": true, "name": "", "songCount": 3, "duration": 300 }, { - "id": "al-12", - "coverArt": "al-12", - "artist": "artist-2", + "id": "al-3", + "coverArt": "al-3", + "artist": "artist-0", + "created": "2019-11-30T00:00:00Z", + "title": "album-0", + "album": "", + "parent": "al-2", + "isDir": true, + "name": "", + "songCount": 3, + "duration": 300 + }, + { + "id": "al-8", + "coverArt": "al-8", + "artist": "artist-1", "created": "2019-11-30T00:00:00Z", "title": "album-1", "album": "", - "parent": "al-10", + "parent": "al-6", "isDir": true, "name": "", "songCount": 3, "duration": 300 }, { - "id": "al-4", - "coverArt": "al-4", + "id": "al-5", + "coverArt": "al-5", "artist": "artist-0", "created": "2019-11-30T00:00:00Z", "title": "album-2", "album": "", - "parent": "al-1", + "parent": "al-2", "isDir": true, "name": "", "songCount": 3, diff --git a/server/ctrlsubsonic/testdata/test_get_album_list_two_alpha_artist b/server/ctrlsubsonic/testdata/test_get_album_list_two_alpha_artist index 0b2abfa4..1f54a5fe 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_list_two_alpha_artist +++ b/server/ctrlsubsonic/testdata/test_get_album_list_two_alpha_artist @@ -6,8 +6,8 @@ "albumList2": { "album": [ { - "id": "al-2", - "coverArt": "al-2", + "id": "al-3", + "coverArt": "al-3", "artistId": "ar-1", "artist": "artist-0", "created": "2019-11-30T00:00:00Z", @@ -19,8 +19,8 @@ "year": 2021 }, { - "id": "al-3", - "coverArt": "al-3", + "id": "al-4", + "coverArt": "al-4", "artistId": "ar-1", "artist": "artist-0", "created": "2019-11-30T00:00:00Z", @@ -32,8 +32,8 @@ "year": 2021 }, { - "id": "al-4", - "coverArt": "al-4", + "id": "al-5", + "coverArt": "al-5", "artistId": "ar-1", "artist": "artist-0", "created": "2019-11-30T00:00:00Z", diff --git a/server/ctrlsubsonic/testdata/test_get_album_list_two_alpha_name b/server/ctrlsubsonic/testdata/test_get_album_list_two_alpha_name index 2c80d215..ded7e5cb 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_list_two_alpha_name +++ b/server/ctrlsubsonic/testdata/test_get_album_list_two_alpha_name @@ -6,8 +6,8 @@ "albumList2": { "album": [ { - "id": "al-2", - "coverArt": "al-2", + "id": "al-3", + "coverArt": "al-3", "artistId": "ar-1", "artist": "artist-0", "created": "2019-11-30T00:00:00Z", @@ -45,8 +45,8 @@ "year": 2021 }, { - "id": "al-3", - "coverArt": "al-3", + "id": "al-4", + "coverArt": "al-4", "artistId": "ar-1", "artist": "artist-0", "created": "2019-11-30T00:00:00Z", @@ -84,8 +84,8 @@ "year": 2021 }, { - "id": "al-4", - "coverArt": "al-4", + "id": "al-5", + "coverArt": "al-5", "artistId": "ar-1", "artist": "artist-0", "created": "2019-11-30T00:00:00Z", diff --git a/server/ctrlsubsonic/testdata/test_get_album_list_two_newest b/server/ctrlsubsonic/testdata/test_get_album_list_two_newest index 0b2abfa4..1f54a5fe 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_list_two_newest +++ b/server/ctrlsubsonic/testdata/test_get_album_list_two_newest @@ -6,8 +6,8 @@ "albumList2": { "album": [ { - "id": "al-2", - "coverArt": "al-2", + "id": "al-3", + "coverArt": "al-3", "artistId": "ar-1", "artist": "artist-0", "created": "2019-11-30T00:00:00Z", @@ -19,8 +19,8 @@ "year": 2021 }, { - "id": "al-3", - "coverArt": "al-3", + "id": "al-4", + "coverArt": "al-4", "artistId": "ar-1", "artist": "artist-0", "created": "2019-11-30T00:00:00Z", @@ -32,8 +32,8 @@ "year": 2021 }, { - "id": "al-4", - "coverArt": "al-4", + "id": "al-5", + "coverArt": "al-5", "artistId": "ar-1", "artist": "artist-0", "created": "2019-11-30T00:00:00Z", diff --git a/server/ctrlsubsonic/testdata/test_get_album_list_two_random b/server/ctrlsubsonic/testdata/test_get_album_list_two_random index 11f0e214..f5bd0048 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_list_two_random +++ b/server/ctrlsubsonic/testdata/test_get_album_list_two_random @@ -6,53 +6,53 @@ "albumList2": { "album": [ { - "id": "al-4", - "coverArt": "al-4", + "id": "al-3", + "coverArt": "al-3", "artistId": "ar-1", "artist": "artist-0", "created": "2019-11-30T00:00:00Z", "title": "", "album": "", - "name": "album-2", + "name": "album-0", "songCount": 3, "duration": 300, "year": 2021 }, { - "id": "al-2", - "coverArt": "al-2", + "id": "al-5", + "coverArt": "al-5", "artistId": "ar-1", "artist": "artist-0", "created": "2019-11-30T00:00:00Z", "title": "", "album": "", - "name": "album-0", + "name": "album-2", "songCount": 3, "duration": 300, "year": 2021 }, { - "id": "al-12", - "coverArt": "al-12", + "id": "al-11", + "coverArt": "al-11", "artistId": "ar-3", "artist": "artist-2", "created": "2019-11-30T00:00:00Z", "title": "", "album": "", - "name": "album-1", + "name": "album-0", "songCount": 3, "duration": 300, "year": 2021 }, { - "id": "al-3", - "coverArt": "al-3", - "artistId": "ar-1", - "artist": "artist-0", + "id": "al-9", + "coverArt": "al-9", + "artistId": "ar-2", + "artist": "artist-1", "created": "2019-11-30T00:00:00Z", "title": "", "album": "", - "name": "album-1", + "name": "album-2", "songCount": 3, "duration": 300, "year": 2021 @@ -71,14 +71,14 @@ "year": 2021 }, { - "id": "al-7", - "coverArt": "al-7", - "artistId": "ar-2", - "artist": "artist-1", + "id": "al-4", + "coverArt": "al-4", + "artistId": "ar-1", + "artist": "artist-0", "created": "2019-11-30T00:00:00Z", "title": "", "album": "", - "name": "album-0", + "name": "album-1", "songCount": 3, "duration": 300, "year": 2021 @@ -97,10 +97,10 @@ "year": 2021 }, { - "id": "al-11", - "coverArt": "al-11", - "artistId": "ar-3", - "artist": "artist-2", + "id": "al-7", + "coverArt": "al-7", + "artistId": "ar-2", + "artist": "artist-1", "created": "2019-11-30T00:00:00Z", "title": "", "album": "", @@ -110,14 +110,14 @@ "year": 2021 }, { - "id": "al-9", - "coverArt": "al-9", - "artistId": "ar-2", - "artist": "artist-1", + "id": "al-12", + "coverArt": "al-12", + "artistId": "ar-3", + "artist": "artist-2", "created": "2019-11-30T00:00:00Z", "title": "", "album": "", - "name": "album-2", + "name": "album-1", "songCount": 3, "duration": 300, "year": 2021 diff --git a/server/ctrlsubsonic/testdata/test_get_album_with_cover b/server/ctrlsubsonic/testdata/test_get_album_with_cover index 1b7d1619..9fc6e92b 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_with_cover +++ b/server/ctrlsubsonic/testdata/test_get_album_with_cover @@ -11,14 +11,14 @@ "created": "2019-11-30T00:00:00Z", "title": "", "album": "", - "name": "album-1", + "name": "album-0", "songCount": 3, "duration": 300, "year": 2021, "song": [ { - "id": "tr-4", - "album": "album-1", + "id": "tr-1", + "album": "album-0", "albumId": "al-3", "artist": "artist-0", "artistId": "ar-1", @@ -30,7 +30,7 @@ "isDir": false, "isVideo": false, "parent": "al-3", - "path": "artist-0/album-1/track-0.flac", + "path": "artist-0/album-0/track-0.flac", "suffix": "flac", "title": "title-0", "track": 1, @@ -39,8 +39,8 @@ "year": 2021 }, { - "id": "tr-5", - "album": "album-1", + "id": "tr-2", + "album": "album-0", "albumId": "al-3", "artist": "artist-0", "artistId": "ar-1", @@ -52,7 +52,7 @@ "isDir": false, "isVideo": false, "parent": "al-3", - "path": "artist-0/album-1/track-1.flac", + "path": "artist-0/album-0/track-1.flac", "suffix": "flac", "title": "title-1", "track": 1, @@ -61,8 +61,8 @@ "year": 2021 }, { - "id": "tr-6", - "album": "album-1", + "id": "tr-3", + "album": "album-0", "albumId": "al-3", "artist": "artist-0", "artistId": "ar-1", @@ -74,7 +74,7 @@ "isDir": false, "isVideo": false, "parent": "al-3", - "path": "artist-0/album-1/track-2.flac", + "path": "artist-0/album-0/track-2.flac", "suffix": "flac", "title": "title-2", "track": 1, diff --git a/server/ctrlsubsonic/testdata/test_get_album_without_cover b/server/ctrlsubsonic/testdata/test_get_album_without_cover index 80c63535..a71d2c82 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_without_cover +++ b/server/ctrlsubsonic/testdata/test_get_album_without_cover @@ -5,84 +5,12 @@ "type": "gonic", "album": { "id": "al-2", - "coverArt": "al-2", - "artistId": "ar-1", - "artist": "artist-0", "created": "2019-11-30T00:00:00Z", "title": "", "album": "", - "name": "album-0", - "songCount": 3, - "duration": 300, - "year": 2021, - "song": [ - { - "id": "tr-1", - "album": "album-0", - "albumId": "al-2", - "artist": "artist-0", - "artistId": "ar-1", - "bitRate": 100, - "contentType": "audio/x-flac", - "coverArt": "al-2", - "created": "2019-11-30T00:00:00Z", - "duration": 100, - "isDir": false, - "isVideo": false, - "parent": "al-2", - "path": "artist-0/album-0/track-0.flac", - "suffix": "flac", - "title": "title-0", - "track": 1, - "discNumber": 1, - "type": "music", - "year": 2021 - }, - { - "id": "tr-2", - "album": "album-0", - "albumId": "al-2", - "artist": "artist-0", - "artistId": "ar-1", - "bitRate": 100, - "contentType": "audio/x-flac", - "coverArt": "al-2", - "created": "2019-11-30T00:00:00Z", - "duration": 100, - "isDir": false, - "isVideo": false, - "parent": "al-2", - "path": "artist-0/album-0/track-1.flac", - "suffix": "flac", - "title": "title-1", - "track": 1, - "discNumber": 1, - "type": "music", - "year": 2021 - }, - { - "id": "tr-3", - "album": "album-0", - "albumId": "al-2", - "artist": "artist-0", - "artistId": "ar-1", - "bitRate": 100, - "contentType": "audio/x-flac", - "coverArt": "al-2", - "created": "2019-11-30T00:00:00Z", - "duration": 100, - "isDir": false, - "isVideo": false, - "parent": "al-2", - "path": "artist-0/album-0/track-2.flac", - "suffix": "flac", - "title": "title-2", - "track": 1, - "discNumber": 1, - "type": "music", - "year": 2021 - } - ] + "name": "", + "songCount": 0, + "duration": 0 } } } diff --git a/server/ctrlsubsonic/testdata/test_get_artist_id_one b/server/ctrlsubsonic/testdata/test_get_artist_id_one index 320d5fea..3e34cb11 100644 --- a/server/ctrlsubsonic/testdata/test_get_artist_id_one +++ b/server/ctrlsubsonic/testdata/test_get_artist_id_one @@ -9,8 +9,8 @@ "albumCount": 3, "album": [ { - "id": "al-2", - "coverArt": "al-2", + "id": "al-3", + "coverArt": "al-3", "artistId": "ar-1", "artist": "artist-0", "created": "2019-11-30T00:00:00Z", @@ -22,8 +22,8 @@ "year": 2021 }, { - "id": "al-3", - "coverArt": "al-3", + "id": "al-4", + "coverArt": "al-4", "artistId": "ar-1", "artist": "artist-0", "created": "2019-11-30T00:00:00Z", @@ -35,8 +35,8 @@ "year": 2021 }, { - "id": "al-4", - "coverArt": "al-4", + "id": "al-5", + "coverArt": "al-5", "artistId": "ar-1", "artist": "artist-0", "created": "2019-11-30T00:00:00Z", diff --git a/server/ctrlsubsonic/testdata/test_get_indexes_no_args b/server/ctrlsubsonic/testdata/test_get_indexes_no_args index ddff578e..53517a11 100644 --- a/server/ctrlsubsonic/testdata/test_get_indexes_no_args +++ b/server/ctrlsubsonic/testdata/test_get_indexes_no_args @@ -10,8 +10,8 @@ { "name": "a", "artist": [ - { "id": "al-1", "name": "artist-0", "albumCount": 3 }, - { "id": "al-14", "name": "artist-0", "albumCount": 3 }, + { "id": "al-2", "name": "artist-0", "albumCount": 3 }, + { "id": "al-15", "name": "artist-0", "albumCount": 3 }, { "id": "al-6", "name": "artist-1", "albumCount": 3 }, { "id": "al-19", "name": "artist-1", "albumCount": 3 }, { "id": "al-10", "name": "artist-2", "albumCount": 3 }, diff --git a/server/ctrlsubsonic/testdata/test_get_indexes_with_music_folder_1 b/server/ctrlsubsonic/testdata/test_get_indexes_with_music_folder_1 index 30a5952d..91f3b1b0 100644 --- a/server/ctrlsubsonic/testdata/test_get_indexes_with_music_folder_1 +++ b/server/ctrlsubsonic/testdata/test_get_indexes_with_music_folder_1 @@ -10,7 +10,7 @@ { "name": "a", "artist": [ - { "id": "al-1", "name": "artist-0", "albumCount": 3 }, + { "id": "al-2", "name": "artist-0", "albumCount": 3 }, { "id": "al-6", "name": "artist-1", "albumCount": 3 }, { "id": "al-10", "name": "artist-2", "albumCount": 3 } ] diff --git a/server/ctrlsubsonic/testdata/test_get_indexes_with_music_folder_2 b/server/ctrlsubsonic/testdata/test_get_indexes_with_music_folder_2 index 78ee3c17..b8690741 100644 --- a/server/ctrlsubsonic/testdata/test_get_indexes_with_music_folder_2 +++ b/server/ctrlsubsonic/testdata/test_get_indexes_with_music_folder_2 @@ -10,7 +10,7 @@ { "name": "a", "artist": [ - { "id": "al-14", "name": "artist-0", "albumCount": 3 }, + { "id": "al-15", "name": "artist-0", "albumCount": 3 }, { "id": "al-19", "name": "artist-1", "albumCount": 3 }, { "id": "al-23", "name": "artist-2", "albumCount": 3 } ] diff --git a/server/ctrlsubsonic/testdata/test_get_music_directory_with_tracks b/server/ctrlsubsonic/testdata/test_get_music_directory_with_tracks index e1f9b2ea..1f0a0168 100644 --- a/server/ctrlsubsonic/testdata/test_get_music_directory_with_tracks +++ b/server/ctrlsubsonic/testdata/test_get_music_directory_with_tracks @@ -5,12 +5,12 @@ "type": "gonic", "directory": { "id": "al-3", - "parent": "al-1", - "name": "album-1", + "parent": "al-2", + "name": "album-0", "child": [ { - "id": "tr-4", - "album": "album-1", + "id": "tr-1", + "album": "album-0", "artist": "artist-0", "bitRate": 100, "contentType": "audio/x-flac", @@ -20,7 +20,7 @@ "isDir": false, "isVideo": false, "parent": "al-3", - "path": "artist-0/album-1/track-0.flac", + "path": "artist-0/album-0/track-0.flac", "suffix": "flac", "title": "title-0", "track": 1, @@ -28,8 +28,8 @@ "type": "music" }, { - "id": "tr-5", - "album": "album-1", + "id": "tr-2", + "album": "album-0", "artist": "artist-0", "bitRate": 100, "contentType": "audio/x-flac", @@ -39,7 +39,7 @@ "isDir": false, "isVideo": false, "parent": "al-3", - "path": "artist-0/album-1/track-1.flac", + "path": "artist-0/album-0/track-1.flac", "suffix": "flac", "title": "title-1", "track": 1, @@ -47,8 +47,8 @@ "type": "music" }, { - "id": "tr-6", - "album": "album-1", + "id": "tr-3", + "album": "album-0", "artist": "artist-0", "bitRate": 100, "contentType": "audio/x-flac", @@ -58,7 +58,7 @@ "isDir": false, "isVideo": false, "parent": "al-3", - "path": "artist-0/album-1/track-2.flac", + "path": "artist-0/album-0/track-2.flac", "suffix": "flac", "title": "title-2", "track": 1, diff --git a/server/ctrlsubsonic/testdata/test_get_music_directory_without_tracks b/server/ctrlsubsonic/testdata/test_get_music_directory_without_tracks index 4bedd648..bae65e97 100644 --- a/server/ctrlsubsonic/testdata/test_get_music_directory_without_tracks +++ b/server/ctrlsubsonic/testdata/test_get_music_directory_without_tracks @@ -6,64 +6,34 @@ "directory": { "id": "al-2", "parent": "al-1", - "name": "album-0", + "name": "artist-0", "child": [ { - "id": "tr-1", - "album": "album-0", - "artist": "artist-0", - "bitRate": 100, - "contentType": "audio/x-flac", - "coverArt": "al-2", + "id": "al-3", + "coverArt": "al-3", "created": "2019-11-30T00:00:00Z", - "duration": 100, - "isDir": false, + "isDir": true, "isVideo": false, "parent": "al-2", - "path": "artist-0/album-0/track-0.flac", - "suffix": "flac", - "title": "title-0", - "track": 1, - "discNumber": 1, - "type": "music" + "title": "album-0" }, { - "id": "tr-2", - "album": "album-0", - "artist": "artist-0", - "bitRate": 100, - "contentType": "audio/x-flac", - "coverArt": "al-2", + "id": "al-4", + "coverArt": "al-4", "created": "2019-11-30T00:00:00Z", - "duration": 100, - "isDir": false, + "isDir": true, "isVideo": false, "parent": "al-2", - "path": "artist-0/album-0/track-1.flac", - "suffix": "flac", - "title": "title-1", - "track": 1, - "discNumber": 1, - "type": "music" + "title": "album-1" }, { - "id": "tr-3", - "album": "album-0", - "artist": "artist-0", - "bitRate": 100, - "contentType": "audio/x-flac", - "coverArt": "al-2", + "id": "al-5", + "coverArt": "al-5", "created": "2019-11-30T00:00:00Z", - "duration": 100, - "isDir": false, + "isDir": true, "isVideo": false, "parent": "al-2", - "path": "artist-0/album-0/track-2.flac", - "suffix": "flac", - "title": "title-2", - "track": 1, - "discNumber": 1, - "type": "music" + "title": "album-2" } ] } diff --git a/server/ctrlsubsonic/testdata/test_search_three_q_alb b/server/ctrlsubsonic/testdata/test_search_three_q_alb index ebf616b8..e0b20242 100644 --- a/server/ctrlsubsonic/testdata/test_search_three_q_alb +++ b/server/ctrlsubsonic/testdata/test_search_three_q_alb @@ -6,8 +6,8 @@ "searchResult3": { "album": [ { - "id": "al-2", - "coverArt": "al-2", + "id": "al-3", + "coverArt": "al-3", "artistId": "ar-1", "artist": "artist-0", "created": "2019-11-30T00:00:00Z", @@ -19,8 +19,8 @@ "year": 2021 }, { - "id": "al-3", - "coverArt": "al-3", + "id": "al-4", + "coverArt": "al-4", "artistId": "ar-1", "artist": "artist-0", "created": "2019-11-30T00:00:00Z", @@ -32,8 +32,8 @@ "year": 2021 }, { - "id": "al-4", - "coverArt": "al-4", + "id": "al-5", + "coverArt": "al-5", "artistId": "ar-1", "artist": "artist-0", "created": "2019-11-30T00:00:00Z", diff --git a/server/ctrlsubsonic/testdata/test_search_three_q_tra b/server/ctrlsubsonic/testdata/test_search_three_q_tra index d654fa51..11b79de7 100644 --- a/server/ctrlsubsonic/testdata/test_search_three_q_tra +++ b/server/ctrlsubsonic/testdata/test_search_three_q_tra @@ -8,16 +8,16 @@ { "id": "tr-1", "album": "album-0", - "albumId": "al-2", + "albumId": "al-3", "artist": "artist-0", "bitRate": 100, "contentType": "audio/x-flac", - "coverArt": "al-2", + "coverArt": "al-3", "created": "2019-11-30T00:00:00Z", "duration": 100, "isDir": false, "isVideo": false, - "parent": "al-2", + "parent": "al-3", "path": "artist-0/album-0/track-0.flac", "suffix": "flac", "title": "title-0", @@ -29,16 +29,16 @@ { "id": "tr-2", "album": "album-0", - "albumId": "al-2", + "albumId": "al-3", "artist": "artist-0", "bitRate": 100, "contentType": "audio/x-flac", - "coverArt": "al-2", + "coverArt": "al-3", "created": "2019-11-30T00:00:00Z", "duration": 100, "isDir": false, "isVideo": false, - "parent": "al-2", + "parent": "al-3", "path": "artist-0/album-0/track-1.flac", "suffix": "flac", "title": "title-1", @@ -50,16 +50,16 @@ { "id": "tr-3", "album": "album-0", - "albumId": "al-2", + "albumId": "al-3", "artist": "artist-0", "bitRate": 100, "contentType": "audio/x-flac", - "coverArt": "al-2", + "coverArt": "al-3", "created": "2019-11-30T00:00:00Z", "duration": 100, "isDir": false, "isVideo": false, - "parent": "al-2", + "parent": "al-3", "path": "artist-0/album-0/track-2.flac", "suffix": "flac", "title": "title-2", @@ -71,16 +71,16 @@ { "id": "tr-4", "album": "album-1", - "albumId": "al-3", + "albumId": "al-4", "artist": "artist-0", "bitRate": 100, "contentType": "audio/x-flac", - "coverArt": "al-3", + "coverArt": "al-4", "created": "2019-11-30T00:00:00Z", "duration": 100, "isDir": false, "isVideo": false, - "parent": "al-3", + "parent": "al-4", "path": "artist-0/album-1/track-0.flac", "suffix": "flac", "title": "title-0", @@ -92,16 +92,16 @@ { "id": "tr-5", "album": "album-1", - "albumId": "al-3", + "albumId": "al-4", "artist": "artist-0", "bitRate": 100, "contentType": "audio/x-flac", - "coverArt": "al-3", + "coverArt": "al-4", "created": "2019-11-30T00:00:00Z", "duration": 100, "isDir": false, "isVideo": false, - "parent": "al-3", + "parent": "al-4", "path": "artist-0/album-1/track-1.flac", "suffix": "flac", "title": "title-1", @@ -113,16 +113,16 @@ { "id": "tr-6", "album": "album-1", - "albumId": "al-3", + "albumId": "al-4", "artist": "artist-0", "bitRate": 100, "contentType": "audio/x-flac", - "coverArt": "al-3", + "coverArt": "al-4", "created": "2019-11-30T00:00:00Z", "duration": 100, "isDir": false, "isVideo": false, - "parent": "al-3", + "parent": "al-4", "path": "artist-0/album-1/track-2.flac", "suffix": "flac", "title": "title-2", @@ -134,16 +134,16 @@ { "id": "tr-7", "album": "album-2", - "albumId": "al-4", + "albumId": "al-5", "artist": "artist-0", "bitRate": 100, "contentType": "audio/x-flac", - "coverArt": "al-4", + "coverArt": "al-5", "created": "2019-11-30T00:00:00Z", "duration": 100, "isDir": false, "isVideo": false, - "parent": "al-4", + "parent": "al-5", "path": "artist-0/album-2/track-0.flac", "suffix": "flac", "title": "title-0", @@ -155,16 +155,16 @@ { "id": "tr-8", "album": "album-2", - "albumId": "al-4", + "albumId": "al-5", "artist": "artist-0", "bitRate": 100, "contentType": "audio/x-flac", - "coverArt": "al-4", + "coverArt": "al-5", "created": "2019-11-30T00:00:00Z", "duration": 100, "isDir": false, "isVideo": false, - "parent": "al-4", + "parent": "al-5", "path": "artist-0/album-2/track-1.flac", "suffix": "flac", "title": "title-1", @@ -176,16 +176,16 @@ { "id": "tr-9", "album": "album-2", - "albumId": "al-4", + "albumId": "al-5", "artist": "artist-0", "bitRate": 100, "contentType": "audio/x-flac", - "coverArt": "al-4", + "coverArt": "al-5", "created": "2019-11-30T00:00:00Z", "duration": 100, "isDir": false, "isVideo": false, - "parent": "al-4", + "parent": "al-5", "path": "artist-0/album-2/track-2.flac", "suffix": "flac", "title": "title-2", diff --git a/server/ctrlsubsonic/testdata/test_search_two_q_alb b/server/ctrlsubsonic/testdata/test_search_two_q_alb index e66412d6..48865579 100644 --- a/server/ctrlsubsonic/testdata/test_search_two_q_alb +++ b/server/ctrlsubsonic/testdata/test_search_two_q_alb @@ -6,30 +6,30 @@ "searchResult2": { "album": [ { - "id": "al-2", - "coverArt": "al-2", + "id": "al-3", + "coverArt": "al-3", "created": "2019-11-30T00:00:00Z", "isDir": true, "isVideo": false, - "parent": "al-1", + "parent": "al-2", "title": "album-0" }, { - "id": "al-3", - "coverArt": "al-3", + "id": "al-4", + "coverArt": "al-4", "created": "2019-11-30T00:00:00Z", "isDir": true, "isVideo": false, - "parent": "al-1", + "parent": "al-2", "title": "album-1" }, { - "id": "al-4", - "coverArt": "al-4", + "id": "al-5", + "coverArt": "al-5", "created": "2019-11-30T00:00:00Z", "isDir": true, "isVideo": false, - "parent": "al-1", + "parent": "al-2", "title": "album-2" }, { diff --git a/server/ctrlsubsonic/testdata/test_search_two_q_art b/server/ctrlsubsonic/testdata/test_search_two_q_art index 10d33d50..7f6408e7 100644 --- a/server/ctrlsubsonic/testdata/test_search_two_q_art +++ b/server/ctrlsubsonic/testdata/test_search_two_q_art @@ -5,9 +5,9 @@ "type": "gonic", "searchResult2": { "artist": [ - { "id": "al-1", "parent": "al-5", "name": "artist-0" }, - { "id": "al-6", "parent": "al-5", "name": "artist-1" }, - { "id": "al-10", "parent": "al-5", "name": "artist-2" } + { "id": "al-2", "parent": "al-1", "name": "artist-0" }, + { "id": "al-6", "parent": "al-1", "name": "artist-1" }, + { "id": "al-10", "parent": "al-1", "name": "artist-2" } ] } } diff --git a/server/ctrlsubsonic/testdata/test_search_two_q_tra b/server/ctrlsubsonic/testdata/test_search_two_q_tra index 09544d03..e8bbce35 100644 --- a/server/ctrlsubsonic/testdata/test_search_two_q_tra +++ b/server/ctrlsubsonic/testdata/test_search_two_q_tra @@ -11,12 +11,12 @@ "artist": "artist-0", "bitRate": 100, "contentType": "audio/x-flac", - "coverArt": "al-2", + "coverArt": "al-3", "created": "2019-11-30T00:00:00Z", "duration": 100, "isDir": false, "isVideo": false, - "parent": "al-2", + "parent": "al-3", "path": "artist-0/album-0/track-0.flac", "suffix": "flac", "title": "title-0", @@ -30,12 +30,12 @@ "artist": "artist-0", "bitRate": 100, "contentType": "audio/x-flac", - "coverArt": "al-2", + "coverArt": "al-3", "created": "2019-11-30T00:00:00Z", "duration": 100, "isDir": false, "isVideo": false, - "parent": "al-2", + "parent": "al-3", "path": "artist-0/album-0/track-1.flac", "suffix": "flac", "title": "title-1", @@ -49,12 +49,12 @@ "artist": "artist-0", "bitRate": 100, "contentType": "audio/x-flac", - "coverArt": "al-2", + "coverArt": "al-3", "created": "2019-11-30T00:00:00Z", "duration": 100, "isDir": false, "isVideo": false, - "parent": "al-2", + "parent": "al-3", "path": "artist-0/album-0/track-2.flac", "suffix": "flac", "title": "title-2", @@ -68,12 +68,12 @@ "artist": "artist-0", "bitRate": 100, "contentType": "audio/x-flac", - "coverArt": "al-3", + "coverArt": "al-4", "created": "2019-11-30T00:00:00Z", "duration": 100, "isDir": false, "isVideo": false, - "parent": "al-3", + "parent": "al-4", "path": "artist-0/album-1/track-0.flac", "suffix": "flac", "title": "title-0", @@ -87,12 +87,12 @@ "artist": "artist-0", "bitRate": 100, "contentType": "audio/x-flac", - "coverArt": "al-3", + "coverArt": "al-4", "created": "2019-11-30T00:00:00Z", "duration": 100, "isDir": false, "isVideo": false, - "parent": "al-3", + "parent": "al-4", "path": "artist-0/album-1/track-1.flac", "suffix": "flac", "title": "title-1", @@ -106,12 +106,12 @@ "artist": "artist-0", "bitRate": 100, "contentType": "audio/x-flac", - "coverArt": "al-3", + "coverArt": "al-4", "created": "2019-11-30T00:00:00Z", "duration": 100, "isDir": false, "isVideo": false, - "parent": "al-3", + "parent": "al-4", "path": "artist-0/album-1/track-2.flac", "suffix": "flac", "title": "title-2", @@ -125,12 +125,12 @@ "artist": "artist-0", "bitRate": 100, "contentType": "audio/x-flac", - "coverArt": "al-4", + "coverArt": "al-5", "created": "2019-11-30T00:00:00Z", "duration": 100, "isDir": false, "isVideo": false, - "parent": "al-4", + "parent": "al-5", "path": "artist-0/album-2/track-0.flac", "suffix": "flac", "title": "title-0", @@ -144,12 +144,12 @@ "artist": "artist-0", "bitRate": 100, "contentType": "audio/x-flac", - "coverArt": "al-4", + "coverArt": "al-5", "created": "2019-11-30T00:00:00Z", "duration": 100, "isDir": false, "isVideo": false, - "parent": "al-4", + "parent": "al-5", "path": "artist-0/album-2/track-1.flac", "suffix": "flac", "title": "title-1", @@ -163,12 +163,12 @@ "artist": "artist-0", "bitRate": 100, "contentType": "audio/x-flac", - "coverArt": "al-4", + "coverArt": "al-5", "created": "2019-11-30T00:00:00Z", "duration": 100, "isDir": false, "isVideo": false, - "parent": "al-4", + "parent": "al-5", "path": "artist-0/album-2/track-2.flac", "suffix": "flac", "title": "title-2", diff --git a/server/mockfs/mockfs.go b/server/mockfs/mockfs.go index 81e9d6bb..8e3ef123 100644 --- a/server/mockfs/mockfs.go +++ b/server/mockfs/mockfs.go @@ -59,7 +59,7 @@ func new(t *testing.T, dirs []string) *MockFS { } parser := &mreader{map[string]*Tags{}} - scanner := scanner.New(absDirs, true, dbc, ";", parser) + scanner := scanner.New(absDirs, dbc, ";", parser) return &MockFS{ t: t, diff --git a/server/scanner/scanner.go b/server/scanner/scanner.go index c930c768..74b6fa53 100644 --- a/server/scanner/scanner.go +++ b/server/scanner/scanner.go @@ -3,6 +3,7 @@ package scanner import ( "errors" "fmt" + "io/fs" "log" "os" "path/filepath" @@ -13,7 +14,6 @@ import ( "time" "github.com/jinzhu/gorm" - "github.com/karrick/godirwalk" "github.com/rainycape/unidecode" "go.senan.xyz/gonic/multierr" @@ -30,18 +30,16 @@ var ( type Scanner struct { db *db.DB - musicPaths []string - sorted bool + musicDirs []string genreSplit string tagger tags.Reader scanning *int32 } -func New(musicPaths []string, sorted bool, db *db.DB, genreSplit string, tagger tags.Reader) *Scanner { +func New(musicDirs []string, db *db.DB, genreSplit string, tagger tags.Reader) *Scanner { return &Scanner{ db: db, - musicPaths: musicPaths, - sorted: sorted, + musicDirs: musicDirs, genreSplit: genreSplit, tagger: tagger, scanning: new(int32), @@ -76,14 +74,37 @@ func (s *Scanner) ScanAndClean(opts ScanOptions) error { durSince(start), c.seenTracksNew, len(c.seenTracks), itemErrs.Len()) }() - for _, musicPath := range s.musicPaths { - err := s.scanPath(c, opts.IsFull, musicPath) - var subItemErrs *multierr.Err - switch { - case errors.As(err, &subItemErrs): - itemErrs.Extend(subItemErrs.Errors()) - case err != nil: - return fmt.Errorf("scan %q: %w", musicPath, err) + for _, dir := range s.musicDirs { + dirName := filepath.Base(dir) + err := filepath.WalkDir(dir, func(absPath string, d fs.DirEntry, err error) error { + if err != nil { + itemErrs.Add(err) + return nil + } + if !d.IsDir() { + return nil + } + if dir == absPath { + return nil + } + + relPath, _ := filepath.Rel(dir, absPath) + log.Printf("processing folder `%s` `%s`", dirName, relPath) + + tx := s.db.Begin() + if err := s.scanDir(tx, c, opts.IsFull, dir, relPath); err != nil { + itemErrs.Add(fmt.Errorf("%q: %w", absPath, err)) + tx.Rollback() + return nil + } + if err := tx.Commit().Error; err != nil { + return fmt.Errorf("commit tx: %w", err) + } + + return nil + }) + if err != nil { + return fmt.Errorf("walk %q: %w", dir, err) } } @@ -111,67 +132,41 @@ func (s *Scanner) ScanAndClean(opts ScanOptions) error { return nil } -func (s *Scanner) scanPath(c *collected, isFull bool, musicPath string) error { - itemErrs := multierr.Err{} - return godirwalk.Walk(musicPath, &godirwalk.Options{ - Callback: func(_ string, _ *godirwalk.Dirent) error { - return nil - }, - PostChildrenCallback: func(itemPath string, _ *godirwalk.Dirent) error { - return s.callback(c, isFull, musicPath, itemPath) - }, - Unsorted: !s.sorted, - FollowSymbolicLinks: true, - ErrorCallback: func(path string, err error) godirwalk.ErrorAction { - itemErrs.Add(fmt.Errorf("%q: %w", path, err)) - return godirwalk.SkipNode - }, - }) -} - -func (s *Scanner) callback(c *collected, isFull bool, rootAbsPath string, itemAbsPath string) error { - relpath, _ := filepath.Rel(rootAbsPath, itemAbsPath) - log.Printf("processing folder `%s`", relpath) - if rootAbsPath == itemAbsPath { - return nil - } - - gs, err := godirwalk.NewScanner(itemAbsPath) +func (s *Scanner) scanDir(tx *db.DB, c *collected, isFull bool, musicDir string, relPath string) error { + absPath := filepath.Join(musicDir, relPath) + items, err := os.ReadDir(absPath) if err != nil { return err } var tracks []string var cover string - for gs.Scan() { - if isCover(gs.Name()) { - cover = gs.Name() + for _, item := range items { + if isCover(item.Name()) { + cover = item.Name() continue } - if _, ok := mime.FromExtension(ext(gs.Name())); ok { - tracks = append(tracks, gs.Name()) + if _, ok := mime.FromExtension(ext(item.Name())); ok { + tracks = append(tracks, item.Name()) continue } } - tx := s.db.Begin() - defer tx.Commit() - - pdir, pbasename := filepath.Split(filepath.Dir(relpath)) + pdir, pbasename := filepath.Split(filepath.Dir(relPath)) parent := &db.Album{} - if err := tx.Where(db.Album{RootDir: rootAbsPath, LeftPath: pdir, RightPath: pbasename}).FirstOrCreate(parent).Error; err != nil { + if err := tx.Where(db.Album{RootDir: musicDir, LeftPath: pdir, RightPath: pbasename}).FirstOrCreate(parent).Error; err != nil { return fmt.Errorf("first or create parent: %w", err) } c.seenAlbums[parent.ID] = struct{}{} - dir, basename := filepath.Split(relpath) + dir, basename := filepath.Split(relPath) album := &db.Album{} - if err := tx.Where(db.Album{RootDir: rootAbsPath, LeftPath: dir, RightPath: basename}).First(album).Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { + if err := tx.Where(db.Album{RootDir: musicDir, LeftPath: dir, RightPath: basename}).First(album).Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { return fmt.Errorf("find album: %w", err) } - if err := populateAlbumBasics(tx, rootAbsPath, parent, album, dir, basename, cover); err != nil { + if err := populateAlbumBasics(tx, musicDir, parent, album, dir, basename, cover); err != nil { return fmt.Errorf("populate album basics: %w", err) } @@ -179,7 +174,7 @@ func (s *Scanner) callback(c *collected, isFull bool, rootAbsPath string, itemAb sort.Strings(tracks) for i, basename := range tracks { - abspath := filepath.Join(itemAbsPath, basename) + abspath := filepath.Join(musicDir, relPath, basename) if err := s.populateTrackAndAlbumArtists(tx, c, i, album, basename, abspath, isFull); err != nil { return fmt.Errorf("process %q: %w", "", err) } @@ -188,7 +183,7 @@ func (s *Scanner) callback(c *collected, isFull bool, rootAbsPath string, itemAb return nil } -func (s *Scanner) populateTrackAndAlbumArtists(tx *db.DB, c *collected, i int, album *db.Album, basename string, abspath string, isFull bool) error { +func (s *Scanner) populateTrackAndAlbumArtists(tx *db.DB, c *collected, i int, album *db.Album, basename string, absPath string, isFull bool) error { track := &db.Track{AlbumID: album.ID, Filename: filepath.Base(basename)} if err := tx.Where(track).First(track).Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { return fmt.Errorf("query track: %w", err) @@ -196,7 +191,7 @@ func (s *Scanner) populateTrackAndAlbumArtists(tx *db.DB, c *collected, i int, a c.seenTracks[track.ID] = struct{}{} - stat, err := os.Stat(abspath) + stat, err := os.Stat(absPath) if err != nil { return fmt.Errorf("stating %q: %w", basename, err) } @@ -204,7 +199,7 @@ func (s *Scanner) populateTrackAndAlbumArtists(tx *db.DB, c *collected, i int, a return nil } - trags, err := s.tagger.Read(abspath) + trags, err := s.tagger.Read(absPath) if err != nil { return fmt.Errorf("%v: %w", err, ErrReadingTags) } @@ -279,8 +274,8 @@ func populateAlbumBasics(tx *db.DB, rootAbsPath string, parent, album *db.Album, return nil } -func populateTrack(tx *db.DB, album *db.Album, albumArtist *db.Artist, track *db.Track, trags tags.Parser, abspath string, size int) error { - basename := filepath.Base(abspath) +func populateTrack(tx *db.DB, album *db.Album, albumArtist *db.Artist, track *db.Track, trags tags.Parser, absPath string, size int) error { + basename := filepath.Base(absPath) track.Filename = basename track.FilenameUDec = decoded(basename) track.Size = size diff --git a/server/server.go b/server/server.go index f1ecdb5b..d49e040a 100644 --- a/server/server.go +++ b/server/server.go @@ -54,7 +54,7 @@ func New(opts Options) (*Server, error) { tagger := &tags.TagReader{} - scanner := scanner.New(opts.MusicPaths, false, opts.DB, opts.GenreSplit, tagger) + scanner := scanner.New(opts.MusicPaths, opts.DB, opts.GenreSplit, tagger) base := &ctrlbase.Controller{ DB: opts.DB, ProxyPrefix: opts.ProxyPrefix,