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
fc2154ee
Commit
fc2154ee
authored
Oct 20, 2015
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DetachedSong: move code from Update() to LoadFile()
Avoid duplicate AllocatedPath::FromUTF8() invocations in two callers.
parent
76f85e6f
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
15 deletions
+25
-15
DetachedSong.hxx
src/DetachedSong.hxx
+6
-0
SongLoader.cxx
src/SongLoader.cxx
+2
-4
SongUpdate.cxx
src/SongUpdate.cxx
+14
-8
OtherCommands.cxx
src/command/OtherCommands.cxx
+1
-1
test_translate_song.cxx
test/test_translate_song.cxx
+2
-2
No files found.
src/DetachedSong.hxx
View file @
fc2154ee
...
@@ -32,6 +32,7 @@
...
@@ -32,6 +32,7 @@
struct
LightSong
;
struct
LightSong
;
class
Storage
;
class
Storage
;
class
Path
;
class
DetachedSong
{
class
DetachedSong
{
friend
DetachedSong
DatabaseDetachSong
(
const
Storage
&
db
,
friend
DetachedSong
DatabaseDetachSong
(
const
Storage
&
db
,
...
@@ -220,6 +221,11 @@ public:
...
@@ -220,6 +221,11 @@ public:
* @return true on success
* @return true on success
*/
*/
bool
Update
();
bool
Update
();
/**
* Load #tag and #mtime from a local file.
*/
bool
LoadFile
(
Path
path
);
};
};
#endif
#endif
src/SongLoader.cxx
View file @
fc2154ee
...
@@ -54,17 +54,15 @@ SongLoader::LoadFile(const char *path_utf8, Error &error) const
...
@@ -54,17 +54,15 @@ SongLoader::LoadFile(const char *path_utf8, Error &error) const
}
}
#endif
#endif
if
(
client
!=
nullptr
)
{
const
auto
path_fs
=
AllocatedPath
::
FromUTF8
(
path_utf8
,
error
);
const
auto
path_fs
=
AllocatedPath
::
FromUTF8
(
path_utf8
,
error
);
if
(
path_fs
.
IsNull
())
if
(
path_fs
.
IsNull
())
return
nullptr
;
return
nullptr
;
if
(
!
client
->
AllowFile
(
path_fs
,
error
))
if
(
client
!=
nullptr
&&
!
client
->
AllowFile
(
path_fs
,
error
))
return
nullptr
;
return
nullptr
;
}
DetachedSong
*
song
=
new
DetachedSong
(
path_utf8
);
DetachedSong
*
song
=
new
DetachedSong
(
path_utf8
);
if
(
!
song
->
Update
(
))
{
if
(
!
song
->
LoadFile
(
path_fs
))
{
error
.
Set
(
playlist_domain
,
int
(
PlaylistResult
::
NO_SUCH_SONG
),
error
.
Set
(
playlist_domain
,
int
(
PlaylistResult
::
NO_SUCH_SONG
),
"No such file"
);
"No such file"
);
delete
song
;
delete
song
;
...
...
src/SongUpdate.cxx
View file @
fc2154ee
...
@@ -154,27 +154,33 @@ Song::UpdateFileInArchive(const Storage &storage)
...
@@ -154,27 +154,33 @@ Song::UpdateFileInArchive(const Storage &storage)
#endif
#endif
bool
bool
DetachedSong
::
Update
(
)
DetachedSong
::
LoadFile
(
Path
path
)
{
{
if
(
IsAbsoluteFile
())
{
const
AllocatedPath
path_fs
=
AllocatedPath
::
FromUTF8
(
GetRealURI
());
FileInfo
fi
;
FileInfo
fi
;
if
(
!
GetFileInfo
(
path_fs
,
fi
)
||
!
fi
.
IsRegular
())
if
(
!
GetFileInfo
(
path
,
fi
)
||
!
fi
.
IsRegular
())
return
false
;
return
false
;
TagBuilder
tag_builder
;
TagBuilder
tag_builder
;
if
(
!
tag_file_scan
(
path_fs
,
full_tag_handler
,
&
tag_builder
))
if
(
!
tag_file_scan
(
path
,
full_tag_handler
,
&
tag_builder
))
return
false
;
return
false
;
if
(
tag_builder
.
IsEmpty
())
if
(
tag_builder
.
IsEmpty
())
tag_scan_fallback
(
path_fs
,
&
full_tag_handler
,
tag_scan_fallback
(
path
,
&
full_tag_handler
,
&
tag_builder
);
&
tag_builder
);
mtime
=
fi
.
GetModificationTime
();
mtime
=
fi
.
GetModificationTime
();
tag_builder
.
Commit
(
tag
);
tag_builder
.
Commit
(
tag
);
return
true
;
return
true
;
}
bool
DetachedSong
::
Update
()
{
if
(
IsAbsoluteFile
())
{
const
AllocatedPath
path_fs
=
AllocatedPath
::
FromUTF8
(
GetRealURI
());
return
LoadFile
(
path_fs
);
}
else
if
(
IsRemote
())
{
}
else
if
(
IsRemote
())
{
TagBuilder
tag_builder
;
TagBuilder
tag_builder
;
if
(
!
tag_stream_scan
(
uri
.
c_str
(),
full_tag_handler
,
if
(
!
tag_stream_scan
(
uri
.
c_str
(),
full_tag_handler
,
...
...
src/command/OtherCommands.cxx
View file @
fc2154ee
...
@@ -176,7 +176,7 @@ handle_lsinfo(Client &client, Request args, Response &r)
...
@@ -176,7 +176,7 @@ handle_lsinfo(Client &client, Request args, Response &r)
return
print_error
(
r
,
error
);
return
print_error
(
r
,
error
);
DetachedSong
song
(
path_utf8
);
DetachedSong
song
(
path_utf8
);
if
(
!
song
.
Update
(
))
{
if
(
!
song
.
LoadFile
(
path_fs
))
{
r
.
Error
(
ACK_ERROR_NO_EXIST
,
"No such file"
);
r
.
Error
(
ACK_ERROR_NO_EXIST
,
"No such file"
);
return
CommandResult
::
ERROR
;
return
CommandResult
::
ERROR
;
}
}
...
...
test/test_translate_song.cxx
View file @
fc2154ee
...
@@ -121,9 +121,9 @@ DatabaseDetachSong(gcc_unused const Database &db,
...
@@ -121,9 +121,9 @@ DatabaseDetachSong(gcc_unused const Database &db,
}
}
bool
bool
DetachedSong
::
Update
(
)
DetachedSong
::
LoadFile
(
Path
path
)
{
{
if
(
strcmp
(
GetURI
(),
uri1
)
==
0
)
{
if
(
path
.
ToUTF8
()
==
uri1
)
{
SetTag
(
MakeTag1a
());
SetTag
(
MakeTag1a
());
return
true
;
return
true
;
}
}
...
...
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