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
69ad5671
Commit
69ad5671
authored
Mar 24, 2015
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Playlist*: use the BufferedOutputStream API instead of FILE*
parent
f9e0f0d2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
38 deletions
+36
-38
PlaylistFile.cxx
src/PlaylistFile.cxx
+19
-20
PlaylistSave.cxx
src/PlaylistSave.cxx
+14
-11
PlaylistSave.hxx
src/PlaylistSave.hxx
+3
-7
No files found.
src/PlaylistFile.cxx
View file @
69ad5671
...
...
@@ -20,12 +20,15 @@
#include "config.h"
#include "PlaylistFile.hxx"
#include "PlaylistSave.hxx"
#include "PlaylistError.hxx"
#include "db/PlaylistInfo.hxx"
#include "db/PlaylistVector.hxx"
#include "DetachedSong.hxx"
#include "SongLoader.hxx"
#include "Mapper.hxx"
#include "fs/io/TextFile.hxx"
#include "fs/io/FileOutputStream.hxx"
#include "fs/io/BufferedOutputStream.hxx"
#include "config/ConfigGlobal.hxx"
#include "config/ConfigOption.hxx"
#include "config/ConfigDefaults.hxx"
...
...
@@ -229,17 +232,18 @@ SavePlaylistFile(const PlaylistFileContents &contents, const char *utf8path,
if
(
path_fs
.
IsNull
())
return
false
;
F
ILE
*
file
=
FOpen
(
path_fs
,
FOpenMode
::
WriteText
);
if
(
file
==
nullptr
)
{
playlist_errno
(
error
);
F
ileOutputStream
fos
(
path_fs
,
error
);
if
(
!
fos
.
IsDefined
()
)
{
TranslatePlaylistError
(
error
);
return
false
;
}
BufferedOutputStream
bos
(
fos
);
for
(
const
auto
&
uri_utf8
:
contents
)
playlist_print_uri
(
file
,
uri_utf8
.
c_str
());
playlist_print_uri
(
bos
,
uri_utf8
.
c_str
());
fclose
(
file
);
return
true
;
return
bos
.
Flush
(
error
)
&&
fos
.
Commit
(
error
);
}
PlaylistFileContents
...
...
@@ -399,29 +403,24 @@ spl_append_song(const char *utf8path, const DetachedSong &song, Error &error)
if
(
path_fs
.
IsNull
())
return
false
;
FILE
*
file
=
FOpen
(
path_fs
,
FOpenMode
::
AppendText
);
if
(
file
==
nullptr
)
{
playlist_errno
(
error
);
return
false
;
}
struct
stat
st
;
if
(
fstat
(
fileno
(
file
),
&
st
)
<
0
)
{
playlist_errno
(
error
);
fclose
(
file
);
AppendFileOutputStream
fos
(
path_fs
,
error
);
if
(
!
fos
.
IsDefined
())
{
TranslatePlaylistError
(
error
);
return
false
;
}
if
(
st
.
st_size
/
off_t
(
MPD_PATH_MAX
+
1
)
>=
(
off_t
)
playlist_max_length
)
{
fclose
(
file
);
if
(
fos
.
Tell
()
/
(
MPD_PATH_MAX
+
1
)
>=
playlist_max_length
)
{
error
.
Set
(
playlist_domain
,
int
(
PlaylistResult
::
TOO_LARGE
),
"Stored playlist is too large"
);
return
false
;
}
playlist_print_song
(
file
,
song
);
BufferedOutputStream
bos
(
fos
);
fclose
(
file
);
playlist_print_song
(
bos
,
song
);
if
(
!
bos
.
Flush
(
error
)
||
!
fos
.
Commit
(
error
))
return
false
;
idle_add
(
IDLE_STORED_PLAYLIST
);
return
true
;
...
...
src/PlaylistSave.cxx
View file @
69ad5671
...
...
@@ -30,6 +30,8 @@
#include "fs/Traits.hxx"
#include "fs/FileSystem.hxx"
#include "fs/NarrowPath.hxx"
#include "fs/io/FileOutputStream.hxx"
#include "fs/io/BufferedOutputStream.hxx"
#include "util/Alloc.hxx"
#include "util/UriUtil.hxx"
#include "util/Error.hxx"
...
...
@@ -38,7 +40,7 @@
#include <string.h>
void
playlist_print_song
(
FILE
*
file
,
const
DetachedSong
&
song
)
playlist_print_song
(
BufferedOutputStream
&
os
,
const
DetachedSong
&
song
)
{
const
char
*
uri_utf8
=
playlist_saveAbsolutePaths
?
song
.
GetRealURI
()
...
...
@@ -46,11 +48,11 @@ playlist_print_song(FILE *file, const DetachedSong &song)
const
auto
uri_fs
=
AllocatedPath
::
FromUTF8
(
uri_utf8
);
if
(
!
uri_fs
.
IsNull
())
fprintf
(
file
,
"%s
\n
"
,
NarrowPath
(
uri_fs
).
c_str
());
os
.
Format
(
"%s
\n
"
,
NarrowPath
(
uri_fs
).
c_str
());
}
void
playlist_print_uri
(
FILE
*
file
,
const
char
*
uri
)
playlist_print_uri
(
BufferedOutputStream
&
os
,
const
char
*
uri
)
{
auto
path
=
#ifdef ENABLE_DATABASE
...
...
@@ -62,7 +64,7 @@ playlist_print_uri(FILE *file, const char *uri)
AllocatedPath
::
FromUTF8
(
uri
);
if
(
!
path
.
IsNull
())
fprintf
(
file
,
"%s
\n
"
,
NarrowPath
(
path
).
c_str
());
os
.
Format
(
"%s
\n
"
,
NarrowPath
(
path
).
c_str
());
}
bool
...
...
@@ -78,18 +80,19 @@ spl_save_queue(const char *name_utf8, const Queue &queue, Error &error)
return
false
;
}
FILE
*
file
=
FOpen
(
path_fs
,
FOpenMode
::
WriteText
);
if
(
file
==
nullptr
)
{
error
.
FormatErrno
(
"Failed to open %s"
,
path_fs
.
ToUTF8
().
c_str
());
FileOutputStream
fos
(
path_fs
,
error
);
if
(
!
fos
.
IsDefined
())
{
TranslatePlaylistError
(
error
);
return
false
;
}
BufferedOutputStream
bos
(
fos
);
for
(
unsigned
i
=
0
;
i
<
queue
.
GetLength
();
i
++
)
playlist_print_song
(
file
,
queue
.
Get
(
i
));
playlist_print_song
(
bos
,
queue
.
Get
(
i
));
fclose
(
file
);
if
(
!
bos
.
Flush
(
error
)
||
!
fos
.
Commit
(
error
))
return
false
;
idle_add
(
IDLE_STORED_PLAYLIST
);
return
true
;
...
...
src/PlaylistSave.hxx
View file @
69ad5671
...
...
@@ -20,21 +20,17 @@
#ifndef MPD_PLAYLIST_SAVE_H
#define MPD_PLAYLIST_SAVE_H
#include "PlaylistError.hxx"
#include <stdio.h>
struct
Queue
;
struct
playlist
;
struct
PlayerControl
;
class
BufferedOutputStream
;
class
DetachedSong
;
class
Error
;
void
playlist_print_song
(
FILE
*
file
,
const
DetachedSong
&
song
);
playlist_print_song
(
BufferedOutputStream
&
os
,
const
DetachedSong
&
song
);
void
playlist_print_uri
(
FILE
*
fp
,
const
char
*
uri
);
playlist_print_uri
(
BufferedOutputStream
&
os
,
const
char
*
uri
);
/**
* Saves a queue object into a stored playlist file.
...
...
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