Commit Graph

130 Commits

Author SHA1 Message Date
Max Kellermann ea8ae68e6f directory: added directory_is_root()
directory_is_root() is cheaper than
isRootDirectory(directory_get_path()).
2009-01-04 19:08:52 +01:00
Max Kellermann 45597cc571 ls: renamed functions, no CamelCase 2009-01-04 17:46:42 +01:00
Max Kellermann 6a008b52d1 update: removed struct delete_data
The struct delete_data has only one member left and can be eliminated.
2009-01-04 17:28:34 +01:00
Max Kellermann ff72fff68d ls: removed hasMusicSuffix() and get_archive_by_suffix()
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.
2009-01-04 17:26:22 +01:00
Max Kellermann d6b229e35c update: moved code to update_regular_file() 2009-01-04 17:26:18 +01:00
Max Kellermann 599d5820bc update: moved code to directory_exists(), fix typo
Reverse the condition: delete directories which don't exist anymore.
This typo caused a slowdown during partial database update.
2009-01-04 17:26:07 +01:00
Max Kellermann a8dbd8f44f update: don't check for symlinks on WIN32
WIN32 does have some kind of symbolic links (e.g. in NTFS), but the
readlink() function is not available.  Disable symlink checking for
now.
2009-01-03 13:19:58 +01:00
Max Kellermann 48aace1859 event_pipe: moved variable "main_task" to main.c 2009-01-03 13:19:01 +01:00
Max Kellermann 38fb8a01c1 update: use GLib instead of utils.h 2009-01-02 17:22:56 +01:00
Max Kellermann daf7c3db5a mapper: allocate the result of map_directory_child_fs(), map_song_fs()
Don't use fixed stack buffers.
2009-01-02 10:48:55 +01:00
Max Kellermann 72255d580e mapper: allocate the result of map_uri_fs(), map_directory_fs()
Don't use fixed stack buffers.
2009-01-02 10:48:11 +01:00
Max Kellermann b2e3b64483 update: use g_file_test() instead of stat()
If we want to check whether a file is a directory, use GLib's
g_file_test() instead of stat().
2009-01-02 10:47:31 +01:00
Max Kellermann b3e2635ac1 event_pipe: added pipe_event enum and callbacks
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.
2009-01-01 18:22:11 +01:00
Max Kellermann 22bb5a5856 event_pipe: renamed functions from main_notify_* to event_pipe_*
Continuing the previous patch.
2009-01-01 18:12:14 +01:00
Max Kellermann 9f5934d95b main_notify: renamed source to event_pipe.c
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.
2009-01-01 18:12:00 +01:00
Max Kellermann 29500cedff update: use GLib logging 2008-12-29 17:29:49 +01:00
Max Kellermann 95b3430f52 removed os_compat.h
Only include headers which are really needed.  os_compat.h aimed to
make MPD easily portable, but was never actually made portable.
2008-12-29 17:28:32 +01:00
Viliam Mateicka 6ad7be9525 update: fixing empty filenames in archives 2008-12-29 07:26:17 +01:00
Thomas Jansen 248cd50a20 update & main_notify: migrate from pthread to glib threads 2008-12-28 22:09:42 +01:00
Max Kellermann 0fe0425dee disable archive API without plugins
When there are no archive plugins, we do not need the archive API at
all.  Drop all its overhead.
2008-12-27 14:33:41 +01:00
Max Kellermann 9220e0edff Merge branch 'experimental' of git://git.musicpd.org/metyl/mpd
Conflicts:

	configure.ac
	src/ls.h
	src/output/shout_plugin.c
2008-12-27 13:34:51 +01:00
Viliam Mateicka 77946a901f update: adding archive updating related code 2008-12-16 21:42:42 +01:00
Avuton Olrich a25b8acd82 update: default to follow all symlinks
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.
2008-12-08 10:01:20 +01:00
Raphaël Rigo 5b089f85fd update: added options which control symlink behaviour
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()]
2008-11-28 10:57:39 +01:00
Max Kellermann ced4abcd64 update: added update_global_init() and update_global_finish()
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.
2008-11-27 19:34:54 +01:00
Thomas Jansen 3742cf3abb update.c: replaced mpd_unused by G_GNUC_UNUSED 2008-11-24 14:46:10 +01:00
Max Kellermann 116662e5a9 update: fixed shadow warning on "basename"
Renamed the local variable "basename", which shadows the POSIX
function basename().
2008-11-22 14:57:08 +01:00
Konstantin Sobolev 7ac3abf499 update: pass UTF-8 path to skip_symlink()
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.
2008-11-20 18:22:07 +01:00
Max Kellermann a5f8d4386c update: check return values
Nearly all mapper functions can fail and will then return NULL.  Add
checks to all callers.
2008-10-31 16:47:21 +01:00
Max Kellermann ba96920a52 path: replaced mpd_basename() with g_path_get_basename()
GLib's g_path_get_basename() is much more reliable than
mpd_basename().  The latter could be tricked into an assertion
failure.
2008-10-20 22:18:12 +02:00
Max Kellermann fa56ff3d52 update: don't skip hidden files
Skip only the special directory entries "." and "..", don't skip all
other "hidden" files.
2008-10-15 20:51:01 +02:00
Max Kellermann a3e3d2c950 command: added command "idle"
"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.
2008-10-14 22:38:14 +02:00
Max Kellermann 197caee151 update: don't follow relative symlinks
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.
2008-10-14 11:10:54 +02:00
Max Kellermann 5b71d5f6f7 mapper: new song-to-filesystem mapper library
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.
2008-10-14 11:10:49 +02:00
Max Kellermann 94a5a5a985 update: always look up parent directory in updatePath()
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.
2008-10-13 16:55:55 +02:00
Max Kellermann a52343732b update: pass base file name to updateInDirectory()
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.
2008-10-13 16:55:54 +02:00
Max Kellermann 270a6ebd69 update: moved code to make_subdir() 2008-10-13 16:46:51 +02:00
Max Kellermann 3e9ed15e76 update: added delete_name_in()
delete_name_in() is similar to delete_path(), but it does not need to
look up the parent directory.
2008-10-13 16:46:32 +02:00
Eric Wong 3035a3303d update: allow music_root updates to be queued
Previously only updates with subdirectories being
specified could be queued.  No harm in queueing
full updates.
2008-10-13 09:55:03 +02:00
Max Kellermann 817a033f55 update: replaced update_return with global "modified" flag
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.
2008-10-09 19:41:58 +02:00
Max Kellermann b8115f2a5f update: make the variable "progress" static 2008-10-09 19:31:31 +02:00
Max Kellermann da7166bdd2 update: don't print debug message when song was not modified
When a song file was not modified, MPD printed the debug message "not
a directory or music", because the first "if" branch did not return.
2008-10-09 19:20:59 +02:00
Max Kellermann 478d0ba7bb update: fix memory leak in directory_update_init()
When the update queue is full, directory_update_init() did not free
the path argument.
2008-10-09 19:20:54 +02:00
Max Kellermann 4beba26c61 update: make the job id unsigned
Since the return value cannot be -1 anymore, we can make it unsigned.
2008-10-09 19:20:05 +02:00
Max Kellermann f1022bcc12 update: job ID must be positive
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().
2008-10-09 19:17:44 +02:00
Max Kellermann 79a28e5c72 update: check progress!=IDLE in reap_update_task()
When the update task is idle, there is no need to check for deleted
songs.  Return early from reap_update_task().
2008-10-09 19:17:38 +02:00
Max Kellermann 69e34f11f5 update: fixed stack corruption due to pthread_join() call
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.
2008-10-09 19:17:33 +02:00
Max Kellermann b4f1b20fd9 updated: always call removeDeletedFromDirectory()
Removed the local variable "was_empty": don't remember if the
directory is new.  Always call removeDeletedFromDirectory().
2008-10-09 19:17:26 +02:00
Max Kellermann 84b52265a6 update: eliminated addSubDirectoryToDirectory()
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().
2008-10-09 19:17:25 +02:00
Max Kellermann 9604f88fe7 update: make the "song" variable more local 2008-10-09 19:16:21 +02:00
Max Kellermann 78899051c0 update: do the recursive directory check only once
The recursive checks were performed in several functions, and
sometimes a directory was checked twice.
2008-10-09 19:15:56 +02:00
Max Kellermann a9799218ab update: copy stat to new directory
When reading a new directory, copy the stat data (which we have
anyway) to the directory struct.  This may save a stat() in the
future.
2008-10-09 19:14:04 +02:00
Max Kellermann 9935ef4034 update: avoid duplicate stat() calls
Pass a pointer to the stat struct to more functions.
2008-10-09 19:13:03 +02:00
Max Kellermann 953f186c8a update: rewrote updatePath() using updateInDirectory()
updatePath() duplicated a lot of code from the more generic
updateInDirectory().  Eliminate most of updatePath() and call
updateInDirectory().
2008-10-09 19:13:02 +02:00
Max Kellermann 7dd099a60f update: don't export updateDirectory()
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().
2008-10-09 19:11:54 +02:00
Max Kellermann 0677116da0 update: pass const pointer to addSubDirectoryToDirectory()
The stat struct isn't going to be modified, make it const.
2008-10-09 19:11:51 +02:00
Max Kellermann 08c1322089 update: never pass root path to updatePath()
update_task() already checks if it has got a root path.  Extend this
check and in turn remove a check in the inner function updatePath().
2008-10-09 19:11:49 +02:00
Max Kellermann 6b9ffcffe2 database: renamed get_get_song() to db_get_song()
Search'n'replace typo..
2008-10-09 16:26:09 +02:00
Max Kellermann 4409c34a8c update: don't sanitize the path again
directory_update_init() has to be called with a path that is already
sanitized.  Don't call sanitizePathDup() again in updatePath().
2008-10-09 16:22:56 +02:00
Max Kellermann a79bd723e2 update: merged addDirectoryPathToDB() into addParentPathToDB()
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.
2008-10-09 15:48:39 +02:00
Max Kellermann 4990f04ac0 update: make addDirectoryPathToDB() non-recursive
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.
2008-10-09 15:48:07 +02:00
Max Kellermann 8536a97920 update: delete directory after failed update
When a directory cannot be updated, there must be something wrong with
it, and the database contains stale data.  Remove it.
2008-10-09 15:47:59 +02:00
Max Kellermann 0daba6bd43 update: moved code to directory_make_child_checked()
The branching looks a bit complicated in addDirectoryPathToDB() -
improve its readability by moving code to a simplified separate
function.
2008-10-09 15:47:22 +02:00
Max Kellermann 2ae94fec6d update: clear root after error
When the root directory fails to update, its contents are invalid.
Clear it then.
2008-10-09 15:42:30 +02:00
Max Kellermann 2bb7bcc7b6 update: locked delete after update error
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.
2008-10-09 15:41:02 +02:00
Max Kellermann 476578d2a9 update: removed addToDirectory()
Use updateInDirectory() instead of addToDirectory().  Eliminate a
duplicate stat() in updateInDirectory() by calling song_file_update()
directly.
2008-10-09 15:37:21 +02:00
Max Kellermann cbc0764613 directory: added inline wrappers for accessing children
Some tiny utilities... wrappers like these may become helpful when we
introduce locking.
2008-10-09 15:34:07 +02:00
Max Kellermann 68f716a28b directory: moved dirvec struct declaration to dirvec.h
No idea why it was created in directory.h, but it should be in
dirvec.h.
2008-10-09 15:24:05 +02:00
Max Kellermann 22645abc10 directory: fix update in root directory
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.
2008-10-08 11:55:52 +02:00
Max Kellermann e8413541f4 update: fix deadlock in delete_song()
Due to a merge error, reap_update_task() called cond_signal_async()
with a locked mutex.  That always fails.  Use cond_signal_sync()
instead.
2008-10-08 11:36:38 +02:00
Max Kellermann 68977af6e0 directory: eliminate CamelCase
CamelCase is ugly, rename the functions.
2008-10-08 11:07:58 +02:00
Max Kellermann bb8a9533b1 database: renamed functions, "db_" prefix and no CamelCase
Yet another CamelCase removal patch.
2008-10-08 11:07:55 +02:00
Max Kellermann 8a50e8a266 directory: moved code to database.c
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.
2008-10-08 11:07:35 +02:00
Max Kellermann 02e8c000d1 song: song_file_update() returns bool
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.
2008-10-08 11:06:26 +02:00
Max Kellermann 5e7b18f874 song: removed CamelCase
CamelCase is ugly...  rename all functions.
2008-10-08 11:05:34 +02:00
Max Kellermann 5e4be9e495 song: replaced all song constructors
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.
2008-10-08 11:05:25 +02:00
Max Kellermann d562ba5fbb song: converted typedef Song to struct song
Again, a data type which can be forward-declared.
2008-10-08 10:49:11 +02:00
Max Kellermann 25f67da58c directory: converted typedef Directory to struct directory
The struct can be forward-declared by other headers, which relaxes the
header dependencies.
2008-10-08 10:49:05 +02:00
Max Kellermann 3c1142cbcb update: merged exploreDirectory() into updateDirectory()
exploreDirectory() duplicates some code in updateDirectory().  Merge
both functions, and use directory_is_empty() to determine whether
update or explore mode should be used.
2008-10-08 10:48:55 +02:00
Max Kellermann 7b9bed8398 directory: moved code to update.c
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.
2008-10-08 10:48:48 +02:00