Determine the suffix manually, and use decoder_plugin_from_suffix()
and archive_plugin_from_suffix() instead.
This way, song_file_update_inarchive() can be optimized: it does not
have to translate its path.
Make the event_pipe (formerly main_notify) send/receive a set of
events, with a callback for each one.
The default event PIPE_EVENT_SIGNAL does not have a callback. It
is still there for waking up the main thread, when it is waiting for
the player thread.
We are going to migrate away from the concept of notifying the main
thread. There should be events sent to it instead. This patch starts
a series to implement that.
MPD 0.13 and older followed all symbolic links. Although this can be
a security problem (as it has always been), 0.14 should offer the same
default behaviour as 0.13.
The configuration options "follow_outside_symlinks" and
"follow_inside_symlinks" let the user control whether MPD should
follow symbolic links in the music directory.
[mk: converted variables to "bool"; moved configuration to
update_global_init()]
Those two functions are called when MPD starts and exits. It allows
the update library to perform global initialization and
deinitialization. The implementations are currently empty.
skip_symlinks() expects an UTF-8 encoded file name, but
updateDirectory() passed ent->d_name (in file system encoding) to it.
Convert it to UTF-8 first.
"idle" waits until something noteworthy happens on the server,
e.g. song change, playlist modified, database updated. This allows
clients to keep up to date without polling.
Don't follow relative symlinks which point into the music directory.
This allows you to organize music with symbolic links, without MPD
managing separate copies of each song.
The mapper library maps directory and song objects to file system
paths. With this central library, the code mixture in path.c should
be cleaned up, and we will be able to add neat features like aliasing.
By always creating the parent directory, we can use delete_name_in()
without further lookups. The parents which may non exist will be
pruned later. An update request for a non-existing or empty directory
should be quite unusual, so this doesn't add any measurable overhead.
In order to optimize buffer usage, pass only the base file name to
updateInDirectory(). This way, updateInDirectory() may choose when to
allocate a larger buffer for the full path.
There is only once update thread at a time. Make the "modified" flag
global and remove the return values of most functions. Propagating an
error is only useful for updateDirectory(), since updateInDirectory()
will delete failed subdirectories.
The documentation for directory_update_init() was incorrect: a job ID
must be positive, not non-negative. If the update queue is full and
no job was created, it makes more sense to return 0 instead of -1,
because it is more consistent with the return value of isUpdatingDB().
pthread_join() expects a "pointer to a pointer" parameter, but it got
a "pointer to an enum". On AMD64, an enum is smaller than a pointer,
leading to a buffer overflow.
In updateInDirectory(), add new directories immediately and
delete them when they turn out to be empty. This simplifies the code
and allows us to eliminate addSubDirectoryToDirectory().
If the user requests database update during startup, call
directory_update_init(). This should be changed to fully asynchronous
update later.
For this to work, main_notify has to be initialized before db_init().
The algorithm in addDirectoryPathToDB() can be simplified further if
it is combined with the function addParentPathToDB(). Since there is
no other caller of addDirectoryPathToDB(), we can do that. This saves
another large stack buffer.
This recursive function is very dangerous because it allocates a large
buffer on the stack in every iteration. That may be misused to
generate a stack overflow.
When a directory failed to update, it was removed from the database,
without freeing all children and songs (memory leak), and without
locking (race condition). Introduce the functions clear_directory()
and delete_directory(), which do both.
Commit 0bfe7802 broke update for new files in the root directory,
because music_root->path was an empty string and not NULL. There were
some NULL tests missing. Change them to !isRootDirectory(path)
instead of path!=NULL.
Taming the directory.c monster, part II: move the database management
stuff to database. directory.c should only contain code which works
on directory objects.
Instead of returning 0 or -1, return true on success and false on
failure. This seems more natural, and when the C library was
designed, there was no "bool" data type.
Provide separate constructors for creating a remote song, a local
song, and one for loading data from a song file. This way, we can add
more assertions.
exploreDirectory() duplicates some code in updateDirectory(). Merge
both functions, and use directory_is_empty() to determine whether
update or explore mode should be used.
The source directory.c mixes several libraries: directory object
management, database management and database update, resulting in a
1000+ line monster. Move the whole database update code to update.c.