In VLC, loading the medialibrary module (
Open()) is done during VLC start, unless
--no-media-library is passed. The fact that the module is correctly opened determines if the medialib UI should be enabled.
However, the medialib initialization is lazy (
initialize() is called the first time the medialib is needed, i.e. later).
To enforce a single medialib instance, we want to know immediately (on medialibrary module loading) if the single instance file lock can be acquired, to be able to enable/disable the medialib UI as needed. However, the file lock path depends on parameters passed to
ml.pid in the mlFolderPath), which is called later.
Therefore, split initialize() in two parts:
configure(dbPath, mlFolderPath): set the db path and ml folder path
initialize(mlCallback): initialize the database
initialize(dbPath, mlFolderPath, mlCallback) is kept for convenience to do both
initialize(mlCallback) (and make the tests happy).
Then acquire the file lock on
configure() (and return a
bool to let the caller know if the database can be used).
- the feature uses
flock(), so something else is necessary for Windows.
- the file lock is acquired during the
configure()call, which is not obvious from the name.
- the lock is
mlFolderPathdirectory, maybe its named should be derived from
On VLC, this branch disables the medialib if the lock is already acquired): https://code.videolan.org/rom1v/vlc/-/commits/ml_single_instance