Song: make the "parent" attribute mandatory
The Song class is only used for database songs now. A Song without a Directory is not possible anymore.
This commit is contained in:
parent
a506adea41
commit
64465c1318
|
@ -145,7 +145,7 @@ directory_load(TextFile &file, Directory &directory, Error &error)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
directory.AddSong(Song::NewFrom(std::move(*song),
|
directory.AddSong(Song::NewFrom(std::move(*song),
|
||||||
&directory));
|
directory));
|
||||||
delete song;
|
delete song;
|
||||||
} else if (StringStartsWith(line, PLAYLIST_META_BEGIN)) {
|
} else if (StringStartsWith(line, PLAYLIST_META_BEGIN)) {
|
||||||
const char *name = line + sizeof(PLAYLIST_META_BEGIN) - 1;
|
const char *name = line + sizeof(PLAYLIST_META_BEGIN) - 1;
|
||||||
|
|
12
src/Song.cxx
12
src/Song.cxx
|
@ -29,8 +29,8 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
inline Song::Song(const char *_uri, size_t uri_length, Directory *_parent)
|
inline Song::Song(const char *_uri, size_t uri_length, Directory &_parent)
|
||||||
:parent(_parent), mtime(0), start_ms(0), end_ms(0)
|
:parent(&_parent), mtime(0), start_ms(0), end_ms(0)
|
||||||
{
|
{
|
||||||
memcpy(uri, _uri, uri_length + 1);
|
memcpy(uri, _uri, uri_length + 1);
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ inline Song::~Song()
|
||||||
}
|
}
|
||||||
|
|
||||||
static Song *
|
static Song *
|
||||||
song_alloc(const char *uri, Directory *parent)
|
song_alloc(const char *uri, Directory &parent)
|
||||||
{
|
{
|
||||||
size_t uri_length;
|
size_t uri_length;
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ song_alloc(const char *uri, Directory *parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
Song *
|
Song *
|
||||||
Song::NewFrom(DetachedSong &&other, Directory *parent)
|
Song::NewFrom(DetachedSong &&other, Directory &parent)
|
||||||
{
|
{
|
||||||
Song *song = song_alloc(other.GetURI(), parent);
|
Song *song = song_alloc(other.GetURI(), parent);
|
||||||
song->tag = std::move(other.WritableTag());
|
song->tag = std::move(other.WritableTag());
|
||||||
|
@ -65,7 +65,7 @@ Song::NewFrom(DetachedSong &&other, Directory *parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
Song *
|
Song *
|
||||||
Song::NewFile(const char *path, Directory *parent)
|
Song::NewFile(const char *path, Directory &parent)
|
||||||
{
|
{
|
||||||
return song_alloc(path, parent);
|
return song_alloc(path, parent);
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ Song::GetURI() const
|
||||||
{
|
{
|
||||||
assert(*uri);
|
assert(*uri);
|
||||||
|
|
||||||
if (parent == nullptr || parent->IsRoot())
|
if (parent->IsRoot())
|
||||||
return std::string(uri);
|
return std::string(uri);
|
||||||
else {
|
else {
|
||||||
const char *path = parent->GetPath();
|
const char *path = parent->GetPath();
|
||||||
|
|
14
src/Song.hxx
14
src/Song.hxx
|
@ -54,7 +54,7 @@ struct Song {
|
||||||
* the current database plugin does not manage the parent
|
* the current database plugin does not manage the parent
|
||||||
* directory this way.
|
* directory this way.
|
||||||
*/
|
*/
|
||||||
Directory *parent;
|
Directory *const parent;
|
||||||
|
|
||||||
time_t mtime;
|
time_t mtime;
|
||||||
|
|
||||||
|
@ -75,15 +75,15 @@ struct Song {
|
||||||
*/
|
*/
|
||||||
char uri[sizeof(int)];
|
char uri[sizeof(int)];
|
||||||
|
|
||||||
Song(const char *_uri, size_t uri_length, Directory *parent);
|
Song(const char *_uri, size_t uri_length, Directory &parent);
|
||||||
~Song();
|
~Song();
|
||||||
|
|
||||||
gcc_malloc
|
gcc_malloc
|
||||||
static Song *NewFrom(DetachedSong &&other, Directory *parent);
|
static Song *NewFrom(DetachedSong &&other, Directory &parent);
|
||||||
|
|
||||||
/** allocate a new song with a local file name */
|
/** allocate a new song with a local file name */
|
||||||
gcc_malloc
|
gcc_malloc
|
||||||
static Song *NewFile(const char *path_utf8, Directory *parent);
|
static Song *NewFile(const char *path_utf8, Directory &parent);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* allocate a new song structure with a local file name and attempt to
|
* allocate a new song structure with a local file name and attempt to
|
||||||
|
@ -91,11 +91,7 @@ struct Song {
|
||||||
* data, nullptr is returned.
|
* data, nullptr is returned.
|
||||||
*/
|
*/
|
||||||
gcc_malloc
|
gcc_malloc
|
||||||
static Song *LoadFile(const char *path_utf8, Directory *parent);
|
static Song *LoadFile(const char *path_utf8, Directory &parent);
|
||||||
|
|
||||||
static Song *LoadFile(const char *path_utf8, Directory &parent) {
|
|
||||||
return LoadFile(path_utf8, &parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Free();
|
void Free();
|
||||||
|
|
||||||
|
|
|
@ -40,19 +40,18 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
Song *
|
Song *
|
||||||
Song::LoadFile(const char *path_utf8, Directory *parent)
|
Song::LoadFile(const char *path_utf8, Directory &parent)
|
||||||
{
|
{
|
||||||
Song *song;
|
Song *song;
|
||||||
bool ret;
|
bool ret;
|
||||||
|
|
||||||
assert((parent == nullptr) == PathTraitsUTF8::IsAbsolute(path_utf8));
|
|
||||||
assert(!uri_has_scheme(path_utf8));
|
assert(!uri_has_scheme(path_utf8));
|
||||||
assert(strchr(path_utf8, '\n') == nullptr);
|
assert(strchr(path_utf8, '\n') == nullptr);
|
||||||
|
|
||||||
song = NewFile(path_utf8, parent);
|
song = NewFile(path_utf8, parent);
|
||||||
|
|
||||||
//in archive ?
|
//in archive ?
|
||||||
if (parent != nullptr && parent->device == DEVICE_INARCHIVE) {
|
if (parent.device == DEVICE_INARCHIVE) {
|
||||||
ret = song->UpdateFileInArchive();
|
ret = song->UpdateFileInArchive();
|
||||||
} else {
|
} else {
|
||||||
ret = song->UpdateFile();
|
ret = song->UpdateFile();
|
||||||
|
|
|
@ -102,7 +102,7 @@ update_container_file(Directory &directory,
|
||||||
unsigned int tnum = 0;
|
unsigned int tnum = 0;
|
||||||
TagBuilder tag_builder;
|
TagBuilder tag_builder;
|
||||||
while ((vtrack = plugin.container_scan(pathname.c_str(), ++tnum)) != nullptr) {
|
while ((vtrack = plugin.container_scan(pathname.c_str(), ++tnum)) != nullptr) {
|
||||||
Song *song = Song::NewFile(vtrack, contdir);
|
Song *song = Song::NewFile(vtrack, *contdir);
|
||||||
|
|
||||||
// shouldn't be necessary but it's there..
|
// shouldn't be necessary but it's there..
|
||||||
song->mtime = st->st_mtime;
|
song->mtime = st->st_mtime;
|
||||||
|
|
|
@ -69,7 +69,7 @@ update_song_file2(Directory &directory,
|
||||||
if (song == nullptr) {
|
if (song == nullptr) {
|
||||||
FormatDebug(update_domain, "reading %s/%s",
|
FormatDebug(update_domain, "reading %s/%s",
|
||||||
directory.GetPath(), name);
|
directory.GetPath(), name);
|
||||||
song = Song::LoadFile(name, &directory);
|
song = Song::LoadFile(name, directory);
|
||||||
if (song == nullptr) {
|
if (song == nullptr) {
|
||||||
FormatDebug(update_domain,
|
FormatDebug(update_domain,
|
||||||
"ignoring unrecognized file %s/%s",
|
"ignoring unrecognized file %s/%s",
|
||||||
|
|
Loading…
Reference in New Issue