Author Topic: Renaming a monitored network folder in Explorer breaks all file paths  (Read 1898 times)

Zak

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 2450
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.
Last Edit: May 26, 2019, 05:58:15 PM by Zak
Bee excellent to each other...

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34312
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
Last Edit: May 26, 2019, 06:48:38 PM by Steven

Zak

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 2450
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.
Bee excellent to each other...

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34312
by the way, you should be able to correct your library by using the remap folders function

Zak

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 2450
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.
Bee excellent to each other...

Zak

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 2450
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.  :'(
Bee excellent to each other...

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34312
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

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34312
could you run your debug version and also display the value of ChangeType, and also OldName (you already show OldFullName) ?

Zak

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 2450
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.
Bee excellent to each other...

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34312
for the next update i will put in a null name check to exclude the dodgy data


Zak

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 2450
Thanks so much for this. I'll keep repopulating my new NAS library and see how it goes.
Bee excellent to each other...