Consistent rename/delete file cross-platform


#1

With current JUCE, It seems file rename/delete is inconsistent across platforms.

On macOS and Linux if you have a file open, you can rename it or delete it.
Windows will fail due to a missing flag.

It’ll be nice if you could add the missing flag -

I’ve also made a test to make sure behavior is consistent (attached is the Projucer PIP).
It’s a modified JUCE playback code with additional thread that renames a file.
(I’ve also tested deletion behavior)

SharedAudioFileAccess.h (9.5 KB)


#2

Does this enable you to delete a file that you still have open handles to on Windows (like you can on macOS at least?)


#3

y

Exactly. (at least under Windows NT kernel I guess as CreateFile uses NtCreateFile).


#4

This would be great. It’s surprisingly difficult to keep track of what may have a file handle open in a large app. It’s usually a waveform view somewhere in a panel that’s off-screen etc.


#5

This seems like a good request and it’d be good to get parity with the POSIX file systems, the only edge case I can see is if people are relying on the existing behaviour ie. users not being able to mess with opened files via the Explorer.

Is there any reason that you’ve added the flag regardless of the AccessMode in MemoryMappedFile::openInternal? I think we should only add it if readWrite access has been requested.


#6

It’s possible to add some parameter to allow a developer to set it if needed in these cases.
However, JUCE does a lot of things to keep expected behavior across multiple platforms. for example, right-click and left-click are handled by the same callback on all OSes…
I guess in most cases for both a developer and a user getting different behavior across different platform would not be expected.

Our reason for doing that also in read only was that rename/delete isn’t direct file “write” (only headers/indexes are being changed, that’s also happening with lastAccessed on macOS even for “locked” file for example).

So it depends on whether or not read-only files should be able to be renamed/deleted, which the flag enables even only with read-only access. Such files can be renamed/deleted on macOS, for example, so for consistency it makes sense to have the same behavior on Windows.

I guess this should be discussed/decided by the JUCE team.


#7

OK, I’ve added this to develop here.