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
7eae3bc8
Commit
7eae3bc8
authored
Dec 16, 2015
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fs/io/FileOutputStream: use C++ exceptions in Commit()
parent
24b21986
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
61 additions
and
44 deletions
+61
-44
PlaylistFile.cxx
src/PlaylistFile.cxx
+8
-2
PlaylistSave.cxx
src/PlaylistSave.cxx
+3
-1
StateFile.cxx
src/StateFile.cxx
+3
-1
SimpleDatabasePlugin.cxx
src/db/plugins/simple/SimpleDatabasePlugin.cxx
+1
-2
FileOutputStream.cxx
src/fs/io/FileOutputStream.cxx
+21
-23
FileOutputStream.hxx
src/fs/io/FileOutputStream.hxx
+2
-2
RecorderOutputPlugin.cxx
src/output/plugins/RecorderOutputPlugin.cxx
+22
-8
WriteFile.cxx
test/WriteFile.cxx
+1
-5
No files found.
src/PlaylistFile.cxx
View file @
7eae3bc8
...
@@ -239,7 +239,11 @@ SavePlaylistFile(const PlaylistFileContents &contents, const char *utf8path,
...
@@ -239,7 +239,11 @@ SavePlaylistFile(const PlaylistFileContents &contents, const char *utf8path,
for
(
const
auto
&
uri_utf8
:
contents
)
for
(
const
auto
&
uri_utf8
:
contents
)
playlist_print_uri
(
bos
,
uri_utf8
.
c_str
());
playlist_print_uri
(
bos
,
uri_utf8
.
c_str
());
return
bos
.
Flush
(
error
)
&&
fos
.
Commit
(
error
);
if
(
!
bos
.
Flush
(
error
))
return
false
;
fos
.
Commit
();
return
true
;
}
}
PlaylistFileContents
PlaylistFileContents
...
@@ -411,9 +415,11 @@ spl_append_song(const char *utf8path, const DetachedSong &song, Error &error)
...
@@ -411,9 +415,11 @@ spl_append_song(const char *utf8path, const DetachedSong &song, Error &error)
playlist_print_song
(
bos
,
song
);
playlist_print_song
(
bos
,
song
);
if
(
!
bos
.
Flush
(
error
)
||
!
fos
.
Commit
(
error
)
)
if
(
!
bos
.
Flush
(
error
))
return
false
;
return
false
;
fos
.
Commit
();
idle_add
(
IDLE_STORED_PLAYLIST
);
idle_add
(
IDLE_STORED_PLAYLIST
);
return
true
;
return
true
;
}
}
...
...
src/PlaylistSave.cxx
View file @
7eae3bc8
...
@@ -86,9 +86,11 @@ spl_save_queue(const char *name_utf8, const Queue &queue, Error &error)
...
@@ -86,9 +86,11 @@ spl_save_queue(const char *name_utf8, const Queue &queue, Error &error)
for
(
unsigned
i
=
0
;
i
<
queue
.
GetLength
();
i
++
)
for
(
unsigned
i
=
0
;
i
<
queue
.
GetLength
();
i
++
)
playlist_print_song
(
bos
,
queue
.
Get
(
i
));
playlist_print_song
(
bos
,
queue
.
Get
(
i
));
if
(
!
bos
.
Flush
(
error
)
||
!
fos
.
Commit
(
error
)
)
if
(
!
bos
.
Flush
(
error
))
return
false
;
return
false
;
fos
.
Commit
();
idle_add
(
IDLE_STORED_PLAYLIST
);
idle_add
(
IDLE_STORED_PLAYLIST
);
return
true
;
return
true
;
}
}
...
...
src/StateFile.cxx
View file @
7eae3bc8
...
@@ -92,10 +92,12 @@ StateFile::Write()
...
@@ -92,10 +92,12 @@ StateFile::Write()
try
{
try
{
Error
error
;
Error
error
;
FileOutputStream
fos
(
path
);
FileOutputStream
fos
(
path
);
if
(
!
Write
(
fos
,
error
)
||
!
fos
.
Commit
(
error
)
)
{
if
(
!
Write
(
fos
,
error
))
{
LogError
(
error
);
LogError
(
error
);
return
;
return
;
}
}
fos
.
Commit
();
}
catch
(
const
std
::
exception
&
e
)
{
}
catch
(
const
std
::
exception
&
e
)
{
LogError
(
e
);
LogError
(
e
);
}
}
...
...
src/db/plugins/simple/SimpleDatabasePlugin.cxx
View file @
7eae3bc8
...
@@ -411,8 +411,7 @@ SimpleDatabase::Save(Error &error)
...
@@ -411,8 +411,7 @@ SimpleDatabase::Save(Error &error)
}
}
#endif
#endif
if
(
!
fos
.
Commit
(
error
))
fos
.
Commit
();
return
false
;
FileInfo
fi
;
FileInfo
fi
;
if
(
GetFileInfo
(
path
,
fi
))
if
(
GetFileInfo
(
path
,
fi
))
...
...
src/fs/io/FileOutputStream.cxx
View file @
7eae3bc8
...
@@ -72,13 +72,12 @@ BaseFileOutputStream::Write(const void *data, size_t size, Error &error)
...
@@ -72,13 +72,12 @@ BaseFileOutputStream::Write(const void *data, size_t size, Error &error)
return
true
;
return
true
;
}
}
bool
void
FileOutputStream
::
Commit
(
gcc_unused
Error
&
error
)
FileOutputStream
::
Commit
()
{
{
assert
(
IsDefined
());
assert
(
IsDefined
());
Close
();
Close
();
return
true
;
}
}
void
void
...
@@ -162,8 +161,8 @@ BaseFileOutputStream::Write(const void *data, size_t size, Error &error)
...
@@ -162,8 +161,8 @@ BaseFileOutputStream::Write(const void *data, size_t size, Error &error)
return
true
;
return
true
;
}
}
bool
void
FileOutputStream
::
Commit
(
Error
&
error
)
FileOutputStream
::
Commit
()
{
{
assert
(
IsDefined
());
assert
(
IsDefined
());
...
@@ -176,20 +175,20 @@ FileOutputStream::Commit(Error &error)
...
@@ -176,20 +175,20 @@ FileOutputStream::Commit(Error &error)
snprintf
(
fd_path
,
sizeof
(
fd_path
),
"/proc/self/fd/%d"
,
snprintf
(
fd_path
,
sizeof
(
fd_path
),
"/proc/self/fd/%d"
,
GetFD
().
Get
());
GetFD
().
Get
());
if
(
linkat
(
AT_FDCWD
,
fd_path
,
AT_FDCWD
,
GetPath
().
c_str
(),
if
(
linkat
(
AT_FDCWD
,
fd_path
,
AT_FDCWD
,
GetPath
().
c_str
(),
AT_SYMLINK_FOLLOW
)
<
0
)
{
AT_SYMLINK_FOLLOW
)
<
0
)
error
.
FormatErrno
(
"Failed to commit %s"
,
throw
FormatErrno
(
"Failed to commit %s"
,
GetPath
().
c_str
());
GetPath
().
c_str
());
Close
();
return
false
;
}
}
}
#endif
#endif
bool
success
=
Close
();
if
(
!
Close
())
{
if
(
!
success
)
#ifdef WIN32
error
.
FormatErrno
(
"Failed to commit %s"
,
GetPath
().
c_str
());
throw
FormatLastError
(
"Failed to commit %s"
,
GetPath
().
ToUTF8
().
c_str
());
return
success
;
#else
throw
FormatErrno
(
"Failed to commit %s"
,
GetPath
().
c_str
());
#endif
}
}
}
void
void
...
@@ -233,18 +232,17 @@ AppendFileOutputStream::AppendFileOutputStream(Path _path)
...
@@ -233,18 +232,17 @@ AppendFileOutputStream::AppendFileOutputStream(Path _path)
#endif
#endif
}
}
bool
void
AppendFileOutputStream
::
Commit
(
gcc_unused
Error
&
error
)
AppendFileOutputStream
::
Commit
()
{
{
assert
(
IsDefined
());
assert
(
IsDefined
());
if
(
!
Close
())
{
#ifdef WIN32
#ifdef WIN32
return
Close
();
throw
FormatLastError
(
"Failed to commit %s"
,
GetPath
().
ToUTF8
().
c_str
());
#else
#else
bool
success
=
Close
();
throw
FormatErrno
(
"Failed to commit %s"
,
GetPath
().
c_str
());
if
(
!
success
)
error
.
FormatErrno
(
"Failed to commit %s"
,
GetPath
().
c_str
());
return
success
;
#endif
#endif
}
}
}
src/fs/io/FileOutputStream.hxx
View file @
7eae3bc8
...
@@ -139,7 +139,7 @@ public:
...
@@ -139,7 +139,7 @@ public:
Cancel
();
Cancel
();
}
}
bool
Commit
(
Error
&
error
);
void
Commit
(
);
void
Cancel
();
void
Cancel
();
};
};
...
@@ -152,7 +152,7 @@ public:
...
@@ -152,7 +152,7 @@ public:
Close
();
Close
();
}
}
bool
Commit
(
Error
&
error
);
void
Commit
(
);
};
};
#endif
#endif
src/output/plugins/RecorderOutputPlugin.cxx
View file @
7eae3bc8
...
@@ -244,8 +244,14 @@ RecorderOutput::Commit(Error &error)
...
@@ -244,8 +244,14 @@ RecorderOutput::Commit(Error &error)
encoder
->
Close
();
encoder
->
Close
();
if
(
success
&&
!
file
->
Commit
(
error
))
if
(
success
)
{
success
=
false
;
try
{
file
->
Commit
();
}
catch
(...)
{
delete
file
;
throw
;
}
}
delete
file
;
delete
file
;
...
@@ -263,9 +269,13 @@ RecorderOutput::Close()
...
@@ -263,9 +269,13 @@ RecorderOutput::Close()
return
;
return
;
}
}
Error
error
;
try
{
if
(
!
Commit
(
error
))
Error
error
;
LogError
(
error
);
if
(
!
Commit
(
error
))
LogError
(
error
);
}
catch
(
const
std
::
exception
&
e
)
{
LogError
(
e
);
}
if
(
HasDynamicPath
())
{
if
(
HasDynamicPath
())
{
assert
(
!
path
.
IsNull
());
assert
(
!
path
.
IsNull
());
...
@@ -281,9 +291,13 @@ RecorderOutput::FinishFormat()
...
@@ -281,9 +291,13 @@ RecorderOutput::FinishFormat()
if
(
file
==
nullptr
)
if
(
file
==
nullptr
)
return
;
return
;
Error
error
;
try
{
if
(
!
Commit
(
error
))
Error
error
;
LogError
(
error
);
if
(
!
Commit
(
error
))
LogError
(
error
);
}
catch
(
const
std
::
exception
&
e
)
{
LogError
(
e
);
}
file
=
nullptr
;
file
=
nullptr
;
path
.
SetNull
();
path
.
SetNull
();
...
...
test/WriteFile.cxx
View file @
7eae3bc8
...
@@ -61,16 +61,12 @@ main(int argc, char **argv)
...
@@ -61,16 +61,12 @@ main(int argc, char **argv)
const
Path
path
=
Path
::
FromFS
(
argv
[
1
]);
const
Path
path
=
Path
::
FromFS
(
argv
[
1
]);
try
{
try
{
Error
error
;
FileOutputStream
fos
(
path
);
FileOutputStream
fos
(
path
);
if
(
!
Copy
(
fos
,
STDIN_FILENO
))
if
(
!
Copy
(
fos
,
STDIN_FILENO
))
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
if
(
!
fos
.
Commit
(
error
))
{
fos
.
Commit
();
fprintf
(
stderr
,
"%s
\n
"
,
error
.
GetMessage
());
return
EXIT_FAILURE
;
}
return
EXIT_SUCCESS
;
return
EXIT_SUCCESS
;
}
catch
(
const
std
::
exception
&
e
)
{
}
catch
(
const
std
::
exception
&
e
)
{
...
...
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