1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-18 10:04:20 +03:00

test: Implement a file-backed IO sink in the runner.

This commit is contained in:
Petr Rockai 2014-06-27 00:53:36 +02:00
parent bdd0bc83eb
commit f53fcc0746

View File

@ -95,6 +95,8 @@ struct FdSink : Sink {
}
virtual void sync() {
if ( killed )
return;
while ( !stream.empty() )
outline( true );
}
@ -107,6 +109,26 @@ struct FdSink : Sink {
FdSink( int _fd ) : fd( _fd ), killed( false ) {}
};
struct FileSink : FdSink {
std::string file;
FileSink( std::string n ) : FdSink( -1 ), file( n ) {}
void sync() {
if ( fd < 0 && !killed ) {
fd = open( file.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644 );
if ( fd < 0 )
killed = true;
}
FdSink::sync();
}
~FileSink() {
if ( fd >= 0 ) {
fsync( fd );
close( fd );
}
}
};
struct Observer : Sink {
Observer() {}
void push( std::string ) {}