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,
for
(
const
auto
&
uri_utf8
:
contents
)
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
...
...
@@ -411,9 +415,11 @@ spl_append_song(const char *utf8path, const DetachedSong &song, Error &error)
playlist_print_song
(
bos
,
song
);
if
(
!
bos
.
Flush
(
error
)
||
!
fos
.
Commit
(
error
)
)
if
(
!
bos
.
Flush
(
error
))
return
false
;
fos
.
Commit
();
idle_add
(
IDLE_STORED_PLAYLIST
);
return
true
;
}
...
...
src/PlaylistSave.cxx
View file @
7eae3bc8
...
...
@@ -86,9 +86,11 @@ spl_save_queue(const char *name_utf8, const Queue &queue, Error &error)
for
(
unsigned
i
=
0
;
i
<
queue
.
GetLength
();
i
++
)
playlist_print_song
(
bos
,
queue
.
Get
(
i
));
if
(
!
bos
.
Flush
(
error
)
||
!
fos
.
Commit
(
error
)
)
if
(
!
bos
.
Flush
(
error
))
return
false
;
fos
.
Commit
();
idle_add
(
IDLE_STORED_PLAYLIST
);
return
true
;
}
...
...
src/StateFile.cxx
View file @
7eae3bc8
...
...
@@ -92,10 +92,12 @@ StateFile::Write()
try
{
Error
error
;
FileOutputStream
fos
(
path
);
if
(
!
Write
(
fos
,
error
)
||
!
fos
.
Commit
(
error
)
)
{
if
(
!
Write
(
fos
,
error
))
{
LogError
(
error
);
return
;
}
fos
.
Commit
();
}
catch
(
const
std
::
exception
&
e
)
{
LogError
(
e
);
}
...
...
src/db/plugins/simple/SimpleDatabasePlugin.cxx
View file @
7eae3bc8
...
...
@@ -411,8 +411,7 @@ SimpleDatabase::Save(Error &error)
}
#endif
if
(
!
fos
.
Commit
(
error
))
return
false
;
fos
.
Commit
();
FileInfo
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)
return
true
;
}
bool
FileOutputStream
::
Commit
(
gcc_unused
Error
&
error
)
void
FileOutputStream
::
Commit
()
{
assert
(
IsDefined
());
Close
();
return
true
;
}
void
...
...
@@ -162,8 +161,8 @@ BaseFileOutputStream::Write(const void *data, size_t size, Error &error)
return
true
;
}
bool
FileOutputStream
::
Commit
(
Error
&
error
)
void
FileOutputStream
::
Commit
()
{
assert
(
IsDefined
());
...
...
@@ -176,20 +175,20 @@ FileOutputStream::Commit(Error &error)
snprintf
(
fd_path
,
sizeof
(
fd_path
),
"/proc/self/fd/%d"
,
GetFD
().
Get
());
if
(
linkat
(
AT_FDCWD
,
fd_path
,
AT_FDCWD
,
GetPath
().
c_str
(),
AT_SYMLINK_FOLLOW
)
<
0
)
{
error
.
FormatErrno
(
"Failed to commit %s"
,
AT_SYMLINK_FOLLOW
)
<
0
)
throw
FormatErrno
(
"Failed to commit %s"
,
GetPath
().
c_str
());
Close
();
return
false
;
}
}
#endif
bool
success
=
Close
();
if
(
!
success
)
error
.
FormatErrno
(
"Failed to commit %s"
,
GetPath
().
c_str
());
return
success
;
if
(
!
Close
())
{
#ifdef WIN32
throw
FormatLastError
(
"Failed to commit %s"
,
GetPath
().
ToUTF8
().
c_str
());
#else
throw
FormatErrno
(
"Failed to commit %s"
,
GetPath
().
c_str
());
#endif
}
}
void
...
...
@@ -233,18 +232,17 @@ AppendFileOutputStream::AppendFileOutputStream(Path _path)
#endif
}
bool
AppendFileOutputStream
::
Commit
(
gcc_unused
Error
&
error
)
void
AppendFileOutputStream
::
Commit
()
{
assert
(
IsDefined
());
if
(
!
Close
())
{
#ifdef WIN32
return
Close
();
throw
FormatLastError
(
"Failed to commit %s"
,
GetPath
().
ToUTF8
().
c_str
());
#else
bool
success
=
Close
();
if
(
!
success
)
error
.
FormatErrno
(
"Failed to commit %s"
,
GetPath
().
c_str
());
return
success
;
throw
FormatErrno
(
"Failed to commit %s"
,
GetPath
().
c_str
());
#endif
}
}
src/fs/io/FileOutputStream.hxx
View file @
7eae3bc8
...
...
@@ -139,7 +139,7 @@ public:
Cancel
();
}
bool
Commit
(
Error
&
error
);
void
Commit
(
);
void
Cancel
();
};
...
...
@@ -152,7 +152,7 @@ public:
Close
();
}
bool
Commit
(
Error
&
error
);
void
Commit
(
);
};
#endif
src/output/plugins/RecorderOutputPlugin.cxx
View file @
7eae3bc8
...
...
@@ -244,8 +244,14 @@ RecorderOutput::Commit(Error &error)
encoder
->
Close
();
if
(
success
&&
!
file
->
Commit
(
error
))
success
=
false
;
if
(
success
)
{
try
{
file
->
Commit
();
}
catch
(...)
{
delete
file
;
throw
;
}
}
delete
file
;
...
...
@@ -263,9 +269,13 @@ RecorderOutput::Close()
return
;
}
Error
error
;
if
(
!
Commit
(
error
))
LogError
(
error
);
try
{
Error
error
;
if
(
!
Commit
(
error
))
LogError
(
error
);
}
catch
(
const
std
::
exception
&
e
)
{
LogError
(
e
);
}
if
(
HasDynamicPath
())
{
assert
(
!
path
.
IsNull
());
...
...
@@ -281,9 +291,13 @@ RecorderOutput::FinishFormat()
if
(
file
==
nullptr
)
return
;
Error
error
;
if
(
!
Commit
(
error
))
LogError
(
error
);
try
{
Error
error
;
if
(
!
Commit
(
error
))
LogError
(
error
);
}
catch
(
const
std
::
exception
&
e
)
{
LogError
(
e
);
}
file
=
nullptr
;
path
.
SetNull
();
...
...
test/WriteFile.cxx
View file @
7eae3bc8
...
...
@@ -61,16 +61,12 @@ main(int argc, char **argv)
const
Path
path
=
Path
::
FromFS
(
argv
[
1
]);
try
{
Error
error
;
FileOutputStream
fos
(
path
);
if
(
!
Copy
(
fos
,
STDIN_FILENO
))
return
EXIT_FAILURE
;
if
(
!
fos
.
Commit
(
error
))
{
fprintf
(
stderr
,
"%s
\n
"
,
error
.
GetMessage
());
return
EXIT_FAILURE
;
}
fos
.
Commit
();
return
EXIT_SUCCESS
;
}
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