Commit Graph

130 Commits

Author SHA1 Message Date
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