getmusicbee.com

Support => Bug Reports => Topic started by: Zak on May 26, 2019, 05:48:54 PM

Title: Renaming a monitored network folder in Explorer breaks all file paths
Post by: Zak on May 26, 2019, 05:48:54 PM
Renaming a single monitored folder in Windows Explorer may incorrectly update the path of all files in MusicBee.
I've recently bought a new NAS and am gradually recreating a MusicBee library on a mapped network share.

I have MusicBee set to monitor a single folder that contains all of my tagged music:
\\[NAS Name]\Multimedia\Music

For the sake of this example, within that I have these two folders:
\\[NAS Name]\Multimedia\Music\B\Billy Joel\1978 - 52nd Street\
\\[NAS Name]\Multimedia\Music\J\Jeff Wayne\1978 - War of the Worlds

The first track in the first folder has this path:
\\[NAS Name]\Multimedia\Music\B\Billy Joel\1978 - 52nd Street\01 - Big Shot.flac

If I use Windows Explorer to rename the second folder to this:
\\[NAS Name]\Multimedia\Music\J\Jeff Wayne\1978 - War of the Worlds [Test]

MusicBee's status bar shows:
Monitored folders: 4,492 files updated

(which is every file in my library)

The path of the previous file in the MusicBee tag editor now shows as:
\\[NAS Name]\Multimedia\Music\J\Jeff Wayne\1978 - War of the Worlds [Test]\B\Billy Joel\1978 - 52nd Street\01 - Big Shot.flac

Somehow, the portion of the renamed folder path below the monitored folder (in bold) is being inserted into every file path.

I didn't notice this when I had my music stored on a local drive, so maybe it's a bug that only affects network shares.
Also, it doesn't happen every time but I have seen it when renaming folders in both the Library and Inbox. Hopefully, there's something obvious that can be fixed. If not, I'll keep testing and try to work out some more specific steps to reproduce the problem.

-edit-
Sorry, should have mentioned I'm using 3.3.7077.
Title: Re: Renaming a monitored network folder in Explorer breaks all file paths
Post by: Steven on May 26, 2019, 06:33:44 PM
Trying now, i cannot reproduce this issue, nor can i see how it would incorrectly happen from looking at the code. Its the sort of thing I would have expected to be reported a very long time ago.
For what you are reporting, it appears that Windows reported the rename from folder as:
\\[NAS Name]\Multimedia\Music\
and rename to folder as:
\\[NAS Name]\Multimedia\Music\J\Jeff Wayne\1978 - War of the Worlds [Test]\

Are you able to set up a small test library and reliably reproduce the issue?
If so I will give you a debug version to confirm what is going on. However if windows is reporting false information, I dont think i would be able to provide a solution
Title: Re: Renaming a monitored network folder in Explorer breaks all file paths
Post by: Zak on May 27, 2019, 02:19:31 AM
I agree that it seems a strange thing not to have been mentioned before.
At work now, but I'll try (hopefully) tonight with a smaller test library and report back.
Title: Re: Renaming a monitored network folder in Explorer breaks all file paths
Post by: Steven on May 27, 2019, 11:18:37 AM
by the way, you should be able to correct your library by using the remap folders function
Title: Re: Renaming a monitored network folder in Explorer breaks all file paths
Post by: Zak on June 01, 2019, 03:49:11 PM
Hi. Sorry, busy week so just got around to testing this again now.

I can reproduce the problem on the smallest possible test library - that is, one containing only two folders with one album in each.
Let me know what information I can provide to help.
Title: Re: Renaming a monitored network folder in Explorer breaks all file paths
Post by: Zak on June 01, 2019, 04:33:53 PM
For what you are reporting, it appears that Windows reported the rename from folder as:
\\[NAS Name]\Multimedia\Music\
and rename to folder as:
\\[NAS Name]\Multimedia\Music\J\Jeff Wayne\1978 - War of the Worlds [Test]\

Assuming you're using a FileSystemWatcher, I just compiled this simple console app:

https://docs.microsoft.com/en-us/dotnet/api/system.io.filesystemwatcher?view=netframework-4.8

(except I set the NotifyFilter to only NotifyFilters.DirectoryName)

Running this on my simple test library folder shows that for network shares at least, the FileSystemWatcher is unreliable.
Adding and removing "[Test]" from a monitored folder name, I got the following output:

File: \\[NAS Name]\Multimedia\Music-Test\B\Billy Joel\1978 - 52nd Street renamed to \\[NAS Name]\Multimedia\Music-Test\B\Billy Joel\1978 - 52nd Street [Test]
File: \\[NAS Name]\Multimedia\Music-Test\ renamed to \\[NAS Name]\Multimedia\Music-Test\B\Billy Joel\1978 - 52nd Street [Test]

File: \\[NAS Name]\Multimedia\Music-Test\B\Billy Joel\1978 - 52nd Street [Test] renamed to \\[NAS Name]\Multimedia\Music-Test\B\Billy Joel\1978 - 52nd Street
File: \\[NAS Name]\Multimedia\Music-Test\B\Billy Joel\1978 - 52nd Street [Test] renamed to \\[NAS Name]\Multimedia\Music-Test\B\Billy Joel\1978 - 52nd Street
For some reason, each rename operation raised two events.
And, as you suggested, the second of the four incorrectly reported the original folder name in e.OldFullPath.  :(

Running the same test again:
File: \\[NAS Name]\Multimedia\Music-Test\B\Billy Joel\1978 - 52nd Street renamed to \\[NAS Name]\Multimedia\Music-Test\B\Billy Joel\1978 - 52nd Street [Test]
File: \\[NAS Name]\Multimedia\Music-Test\ renamed to \\[NAS Name]\Multimedia\Music-Test\B\Billy Joel\1978 - 52nd Street [Test]

File: \\[NAS Name]\Multimedia\Music-Test\B\Billy Joel\1978 - 52nd Street [Test] renamed to \\[NAS Name]\Multimedia\Music-Test\B\Billy Joel\1978 - 52nd Street
File: \\[NAS Name]\Multimedia\Music-Test\ renamed to \\[NAS Name]\Multimedia\Music-Test\B\Billy Joel\1978 - 52nd Street
This time, two of the four were wrong, so it's not even consistently buggy.  :'(
Title: Re: Renaming a monitored network folder in Explorer breaks all file paths
Post by: Steven on June 01, 2019, 05:08:26 PM
Thanks for doing those tests and yes MB is using the FileSystemWatcher api.
Unfortunately I think the results mean i wont be able to do anything about it.
It is quite concerning that a windows API like that would be buggy
Title: Re: Renaming a monitored network folder in Explorer breaks all file paths
Post by: Steven on June 01, 2019, 05:46:52 PM
could you run your debug version and also display the value of ChangeType, and also OldName (you already show OldFullName) ?
Title: Re: Renaming a monitored network folder in Explorer breaks all file paths
Post by: Zak on June 01, 2019, 09:18:20 PM
Yep.

Renamed "Test Folder 1" to "Test Folder 2":
ChangeType  : Renamed
OldFullPath : \\[NAS Name]\Multimedia\Music-Test\Test Folder 1
OldName     : Test Folder 1
 > Is null? : False
FullPath    : \\[NAS Name]\Multimedia\Music-Test\Test Folder 2

ChangeType  : Renamed
OldFullPath : \\[NAS Name]\Multimedia\Music-Test\
OldName     :
 > Is null? : True
FullPath    : \\[NAS Name]\Multimedia\Music-Test\Test Folder 2
I tested a dozen times, and in every case OldName on the dodgy notification was a null string.

It also occurred to me that if e.oldFullPath is the same as a top-level monitored Library path it must be incorrect, because a FileSystemWatcher set to monitor subdirectories won't send a notification if that top-level folder is renamed.
Title: Re: Renaming a monitored network folder in Explorer breaks all file paths
Post by: Steven on June 02, 2019, 07:37:20 AM
for the next update i will put in a null name check to exclude the dodgy data
Title: Re: Renaming a monitored network folder in Explorer breaks all file paths
Post by: Steven on June 02, 2019, 10:54:52 AM
https://getmusicbee.com/patches/MusicBee33_Patched.zip
Title: Re: Renaming a monitored network folder in Explorer breaks all file paths
Post by: Zak on June 04, 2019, 05:28:26 AM
Thanks so much for this. I'll keep repopulating my new NAS library and see how it goes.