]> sourceware.org Git - lvm2.git/commitdiff
test: Implement a file-backed IO sink in the runner.
authorPetr Rockai <prockai@redhat.com>
Thu, 26 Jun 2014 22:53:36 +0000 (00:53 +0200)
committerPetr Rockai <prockai@redhat.com>
Thu, 5 Feb 2015 12:47:17 +0000 (13:47 +0100)
test/lib/io.h

index 28e40d8c3c630c5020aa98737181bdcdac1c2ceb..c96382ccc981c69305d627bda42d1aeabea4773b 100644 (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 ) {}
This page took 0.040601 seconds and 5 git commands to generate.