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
7f6e1fbc
Commit
7f6e1fbc
authored
Mar 23, 2015
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fs/io/FileOutputStream: add class AppendFileOutputStream
parent
06827cfc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
0 deletions
+67
-0
FileOutputStream.cxx
src/fs/io/FileOutputStream.cxx
+55
-0
FileOutputStream.hxx
src/fs/io/FileOutputStream.hxx
+12
-0
No files found.
src/fs/io/FileOutputStream.cxx
View file @
7f6e1fbc
...
...
@@ -197,4 +197,59 @@ FileOutputStream::Cancel()
RemoveFile
(
GetPath
());
}
#ifdef WIN32
FileOutputStream
::
FileOutputStream
(
Path
_path
,
Error
&
error
)
:
path
(
_path
),
handle
(
CreateFile
(
path
.
c_str
(),
GENERIC_WRITE
,
0
,
nullptr
,
CREATE_ALWAYS
,
FILE_ATTRIBUTE_NORMAL
|
FILE_FLAG_WRITE_THROUGH
,
nullptr
))
{
if
(
handle
==
INVALID_HANDLE_VALUE
)
{
const
auto
path_utf8
=
path
.
ToUTF8
();
error
.
FormatLastError
(
"Failed to create %s"
,
path_utf8
.
c_str
());
}
}
#else
AppendFileOutputStream
::
AppendFileOutputStream
(
Path
_path
,
Error
&
error
)
:
BaseFileOutputStream
(
_path
)
{
#ifdef WIN32
SetHandle
(
CreateFile
(
path
.
c_str
(),
GENERIC_WRITE
,
0
,
nullptr
,
OPEN_EXISTING
,
FILE_ATTRIBUTE_NORMAL
|
FILE_FLAG_WRITE_THROUGH
,
nullptr
))
if
(
!
IsDefined
())
error
.
FormatLastError
(
"Failed to append to %s"
,
GetPath
().
ToUTF8
().
c_str
());
#else
if
(
!
SetFD
().
Open
(
GetPath
().
c_str
(),
O_WRONLY
|
O_APPEND
))
error
.
FormatErrno
(
"Failed to append to %s"
,
GetPath
().
c_str
());
#endif
}
#endif
bool
AppendFileOutputStream
::
Commit
(
gcc_unused
Error
&
error
)
{
assert
(
IsDefined
());
#ifdef WIN32
return
Close
();
#else
bool
success
=
Close
();
if
(
!
success
)
error
.
FormatErrno
(
"Failed to commit %s"
,
GetPath
().
c_str
());
return
success
;
#endif
}
#endif
src/fs/io/FileOutputStream.hxx
View file @
7f6e1fbc
...
...
@@ -135,4 +135,16 @@ public:
void
Cancel
();
};
class
AppendFileOutputStream
final
:
public
BaseFileOutputStream
{
public
:
AppendFileOutputStream
(
Path
_path
,
Error
&
error
);
~
AppendFileOutputStream
()
{
if
(
IsDefined
())
Close
();
}
bool
Commit
(
Error
&
error
);
};
#endif
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