Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
9fb82f96
Commit
9fb82f96
authored
Jan 15, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DetachedSong: add method Update()
Don't create an intermediate Song instance when all we want is a DetachedSong.
parent
df80deb0
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
55 additions
and
15 deletions
+55
-15
DetachedSong.hxx
src/DetachedSong.hxx
+7
-0
PlaylistEdit.cxx
src/PlaylistEdit.cxx
+3
-5
PlaylistSong.cxx
src/PlaylistSong.cxx
+4
-5
SongUpdate.cxx
src/SongUpdate.cxx
+37
-0
OtherCommands.cxx
src/command/OtherCommands.cxx
+4
-5
No files found.
src/DetachedSong.hxx
View file @
9fb82f96
...
...
@@ -179,6 +179,13 @@ public:
gcc_pure
double
GetDuration
()
const
;
/**
* Update the #tag and #mtime.
*
* @return true on success
*/
bool
Update
();
};
#endif
src/PlaylistEdit.cxx
View file @
9fb82f96
...
...
@@ -61,13 +61,11 @@ PlaylistResult
playlist
::
AppendFile
(
PlayerControl
&
pc
,
const
char
*
path_utf8
,
unsigned
*
added_id
)
{
Song
*
song
=
Song
::
LoadFile
(
path_utf8
,
nullptr
);
if
(
song
==
nullptr
)
DetachedSong
song
(
path_utf8
);
if
(
!
song
.
Update
()
)
return
PlaylistResult
::
NO_SUCH_SONG
;
const
auto
result
=
AppendSong
(
pc
,
DetachedSong
(
*
song
),
added_id
);
song
->
Free
();
return
result
;
return
AppendSong
(
pc
,
std
::
move
(
song
),
added_id
);
}
PlaylistResult
...
...
src/PlaylistSong.cxx
View file @
9fb82f96
...
...
@@ -100,12 +100,11 @@ playlist_check_load_song(const DetachedSong *song, const char *uri, bool secure)
if
(
uri_has_scheme
(
uri
))
{
dest
=
new
DetachedSong
(
uri
);
}
else
if
(
PathTraitsUTF8
::
IsAbsolute
(
uri
)
&&
secure
)
{
Song
*
tmp
=
Song
::
LoadFile
(
uri
,
nullptr
);
if
(
tmp
==
nullptr
)
dest
=
new
DetachedSong
(
uri
);
if
(
!
dest
->
Update
())
{
delete
dest
;
return
nullptr
;
dest
=
new
DetachedSong
(
*
tmp
);
delete
tmp
;
}
}
else
{
const
Database
*
db
=
GetDatabase
();
if
(
db
==
nullptr
)
...
...
src/SongUpdate.cxx
View file @
9fb82f96
...
...
@@ -19,6 +19,7 @@
#include "config.h"
/* must be first for large file support */
#include "Song.hxx"
#include "DetachedSong.hxx"
#include "util/UriUtil.hxx"
#include "Directory.hxx"
#include "Mapper.hxx"
...
...
@@ -126,3 +127,39 @@ Song::UpdateFileInArchive()
tag
=
tag_builder
.
CommitNew
();
return
true
;
}
bool
DetachedSong
::
Update
()
{
if
(
IsAbsoluteFile
())
{
const
AllocatedPath
path_fs
=
AllocatedPath
::
FromUTF8
(
uri
.
c_str
());
struct
stat
st
;
if
(
!
StatFile
(
path_fs
,
st
)
||
!
S_ISREG
(
st
.
st_mode
))
return
false
;
TagBuilder
tag_builder
;
if
(
!
tag_file_scan
(
path_fs
,
full_tag_handler
,
&
tag_builder
))
return
false
;
if
(
tag_builder
.
IsEmpty
())
tag_scan_fallback
(
path_fs
,
&
full_tag_handler
,
&
tag_builder
);
mtime
=
st
.
st_mtime
;
tag_builder
.
Commit
(
tag
);
return
true
;
}
else
if
(
IsRemote
())
{
TagBuilder
tag_builder
;
if
(
!
tag_stream_scan
(
uri
.
c_str
(),
full_tag_handler
,
&
tag_builder
))
return
false
;
mtime
=
0
;
tag_builder
.
Commit
(
tag
);
return
true
;
}
else
// TODO: implement
return
false
;
}
src/command/OtherCommands.cxx
View file @
9fb82f96
...
...
@@ -23,7 +23,7 @@
#include "CommandError.hxx"
#include "UpdateGlue.hxx"
#include "Directory.hxx"
#include "Song.hxx"
#include "
Detached
Song.hxx"
#include "SongPrint.hxx"
#include "TagPrint.hxx"
#include "TagStream.hxx"
...
...
@@ -140,15 +140,14 @@ handle_lsinfo(Client &client, int argc, char *argv[])
if
(
!
client_allow_file
(
client
,
path_fs
,
error
))
return
print_error
(
client
,
error
);
Song
*
song
=
Song
::
LoadFile
(
path_utf8
,
nullptr
);
if
(
song
==
nullptr
)
{
DetachedSong
song
(
path_utf8
);
if
(
!
song
.
Update
()
)
{
command_error
(
client
,
ACK_ERROR_NO_EXIST
,
"No such file"
);
return
CommandResult
::
ERROR
;
}
song_print_info
(
client
,
*
song
);
song
->
Free
();
song_print_info
(
client
,
song
);
return
CommandResult
::
OK
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment