Commit Graph

183 Commits

Author SHA1 Message Date
Max Kellermann
a45922cd66 use g_free() instead of free()
On some platforms, g_free() must be used for memory allocated by
GLib.  This patch intends to correct a lot of occurrences, but is
probably not complete.
2009-01-25 18:47:21 +01:00
Max Kellermann
cc4e0a786d directory: use GLib instead of utils.h 2009-01-02 16:26:19 +01:00
Max Kellermann
8f9d9cc042 directory: directory_free() frees children
directory_free() should free all of its children (subdirectories and
songs).  This way, db_finish() properly frees all allocated memory.
2008-10-31 09:20:02 +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
3b6ff84393 directory: added directory_get_name()
directory_get_name() returns the base name of the directory.
2008-10-13 16:32:39 +02:00
Eric Wong
8d907fb9fa directory: use mpd_sizeof_str_flex_array for path, too
This way we avoid unnecessary heap allocations.
2008-10-13 09:55:00 +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
a0c044df11 diretory: moved code to directory_save.c, directory_print.c
Remove clutter from directory.c.  Everything which saves or loads
to/from the hard disk goes to directory_save.c, and code which sends
directory information to the client is moved into directory_print.c.
2008-10-09 15:23:37 +02:00
Max Kellermann
0bfe7802d2 directory: path must not be NULL
For the root directory, let's set path to an empty string.  This saves
a few checks.
2008-10-08 11:08:16 +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
ba5c9b0375 directory: converted isRootDirectory() to an inline function
The function isRootDirectory() is tiny and can be converted to an
inline function.  Don't allow name==NULL.
2008-10-08 11:06:44 +02:00
Max Kellermann
5e7b18f874 song: removed CamelCase
CamelCase is ugly...  rename all functions.
2008-10-08 11:05:34 +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
e79aacf1db directory: added directory_is_empty()
directory_is_empty() is a tiny inline function which determine if a
directory has any child objects (sub directories or songs).
2008-10-08 10:48:49 +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
Eric Wong
81ce068085 directory: fix return value in removeDeletedFromDirectory
oops :x
2008-10-07 22:11:21 +02:00
Eric Wong
7d8c9cc7e3 directory: serialize song deletes from playlist during update
This makes the update code thread-safe and doesn't penalize
the playlist code by complicating it with complicated and
error-prone locks (and the associated overhead, not everybody
has a thread-implementation as good as NPTL).

The update task blocks during the delete; but the update task is
a slow task anyways so we can block w/o people caring too much.

This was also our only freeSong call site, so remove that
function.

Note that deleting entire directories is not fully thread-safe,
yet; as their traversals are not yet locked.
2008-10-07 22:11:16 +02:00
Eric Wong
2b965a5424 directory: use songvec_for_each for iterators
Get rid of songvec_write so we can enforce proper locking
2008-10-07 22:10:48 +02:00
Eric Wong
8be6026336 dbUtils/directory: traverseAllIn forEachSong returns -1 on error
Being consistent with most UNIX functions...
2008-10-07 22:07:44 +02:00
Eric Wong
0d34815f6c Assert if we don't have song or song->url set
song objects cannot exist without a path or URL
2008-10-07 21:20:34 +02:00
Eric Wong
f1c53fe0ed song: stop storing song_type
We already know if a song is a URL or not based on whether it
has parentDir defined or not.  Hopefully one day in the future
we can drop HTTP support from MPD entirely when an HTTP
filesystem comes along and we can access streams via open(2).
2008-10-06 18:52:13 +02:00
Eric Wong
267b2cd6e6 song: use flex arrays to store song->url
Reduce the number of allocations we make, so there's less
pressure on the allocator and less overhead to keep track
of the allocations in.
2008-10-06 18:46:52 +02:00
Eric Wong
836dcc28c5 directory: reuse existing directory if found on update
Instead of allocating a new one, just reuse an existing
one if one is found when rereading the DB.  This is a small
makes the previous commit work on subdirectories
of the root music directory.

[1] "song: better handling of existing songs when rereading DB"
2008-10-06 18:37:13 +02:00
Eric Wong
37a8239f44 directory: simplify list update handling logic
Now the "update" command can be issued multiple times regardless
of whether the client is in list mode or not.

We serialize the update tasks to prevent updates from trampling
over each other and will spawn another update task
once the current one is finished updating and reaped.

Right now we cap the queue size to 32 which is probably enough (I
bet most people usually run update with no argument anyways);
but we can make it grow/shrink dynamically if needed.  There'll
still be a hard-coded limit to prevent DoS attacks, though.
2008-10-06 18:32:27 +02:00
Eric Wong
19a4803bc9 directory: streamline deletes
Instead of relying on the shortname, just pass the song pointer
to prevent redundant lookups during deletes.
2008-10-06 18:20:53 +02:00
Eric Wong
11245dc119 directory: isRootDirectory() is a one-liner
Improving the signal to noise ratio...
2008-09-29 13:18:27 +02:00
Eric Wong
da79498afd directory: writeDirectoryInfo propagates errors
If a write failed, it's a good sign subsequent writes will fail,
too, so propgate errors all the way up the stack.
2008-09-29 13:17:52 +02:00
Eric Wong
4e15e292e0 directory: make it clear that DIRECTORY_MTIME is deprecated
A long time ago in an mpd far away...
2008-09-29 13:17:48 +02:00
Eric Wong
a0364d38d3 directory: remove "Mp3" references
MPD has supported more audio formats than just MP3
for over five years...
2008-09-29 13:17:42 +02:00
Eric Wong
71b332601a directory: remove shortname arguments everywhere
It was a huge confusing mess of parameter passing around
and around.  Add a few extra assertions to ensure we're
handling parent/child relationships properly.
2008-09-29 13:17:23 +02:00
Eric Wong
3b8bc33a04 directory: replace DirectoryList with dirvec
Small memory reduction compared to songvec since most users have
much fewer dirs than songs, but still nice to have.
2008-09-29 13:11:40 +02:00
Eric Wong
029f607e15 directory: remove unused CPP defines
We no longer for for updates
2008-09-29 12:17:20 +02:00
Eric Wong
6075119f0a songvec_free => songvec_destroy
"free" implies the songvec structure itself is freed,
which is not the case.
2008-09-29 12:17:13 +02:00
Eric Wong
5ec578119f directory.c: kill unnecessary includes 2008-09-29 12:16:57 +02:00
Eric Wong
52a0ea2dc5 directory: update playlist version if updated
If we updated the mpd metadata database; then there's a chance
some of those songs in the playlist will have updated metadata.
So be on the safe side and increment the playlist version number
if _any_ song changed (this is how all released versions of mpd
did it, too).

This bug was introduced recently when making "update" threaded.

Thanks to stonecrest for the bug report.
2008-09-29 12:15:16 +02:00
Eric Wong
74b34f7b61 directory: fix leak introduced with threaded update
Use freeList() instead of free() to free all elements in
the list.
2008-09-23 22:38:39 +02:00
Eric Wong
260e1a9037 Remove EINTR checking for open(2)
open(2) should only interrupt on "slow" devices, afaik...

[mk: still using fopen()]
2008-09-23 22:38:36 +02:00
Eric Wong
5cc5c37856 directory: don't leak file handles if we get a corrupt db 2008-09-23 22:37:40 +02:00
Eric Wong
3f0ae13c4b directory: update do its work inside a thread
A lot of the preparation was needed (and done in previous
months) in making update thread-safe, but here it is.

This was the first thing I made work inside a thread when I
started mpd-uclinux many years ago, and also the last thing I've
done in mainline mpd to work inside a thread, go figure.
2008-09-23 22:37:18 +02:00
Max Kellermann
0f0ac43b8f directory: use enum update_return for return values II
Converted some more functions and their callers to enum update_return.
2008-09-23 22:36:00 +02:00
Eric Wong
986c2f134d directory: use enum update_return for return values
This way we avoid having to document -1, 0, 1
2008-09-23 20:49:05 +02:00
Eric Wong
cce2f93de7 workaround race condition on updates with broken signal blocking
pthreads with our existing signal blocking/handling is broken,
for now just sleep a bit in the child to prevent the CHLD handler
from being called too early.  Also, improve error reporting when
handling SIGCHLD by storing the status to be called in the main
task (which can be logged, since we can't do logging inside the
sig handler).
2008-09-23 20:48:44 +02:00
Eric Wong
0bec1d3807 Replace SongList with struct songvec
Our linked-list implementation is wasteful and the
SongList isn't modified enough to benefit from being a linked
list.  So use a more compact array of song pointers which
saves ~200K on a library with ~9K songs (on x86-32).
2008-09-23 20:48:39 +02:00
Eric Wong
afe6ce7210 directory: remove unused updateMp3Directory() function
It hasn't been used in many years

  commit 3a89afdd80
  Author: Warren Dukes <warren.dukes@gmail.com>
  Date:   Sat Nov 20 20:28:32 2004 +0000

      remove --update-db option

      (SVN r2719)
2008-09-23 20:48:33 +02:00
Eric Wong
27fad52c6b start using prefixcmp()
LOC reduction and less noise makes things easier for
tired old folks to follow.
2008-09-23 20:48:12 +02:00