diff options
author | Bartosz Taudul <wolf.pld@gmail.com> | 2020-09-20 21:04:43 +0300 |
---|---|---|
committer | Bartosz Taudul <wolf.pld@gmail.com> | 2020-09-20 21:04:43 +0300 |
commit | 7da17680aeec06086759d453f326d4879a36266e (patch) | |
tree | 7327c149e97e003f26e6047e8f6ad9456fd9f805 | |
parent | 1e34b22a82fdba417ad51fe95072644365750b43 (diff) |
Prevent overwriting existing files by the capture utility.
-rw-r--r-- | capture/src/capture.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/capture/src/capture.cpp b/capture/src/capture.cpp index 6b911b85..2b40581a 100644 --- a/capture/src/capture.cpp +++ b/capture/src/capture.cpp @@ -9,6 +9,7 @@ #include <stdint.h> #include <stdio.h> #include <stdlib.h> +#include <sys/stat.h> #include "../../common/TracyProtocol.hpp" #include "../../server/TracyFileWrite.hpp" @@ -27,7 +28,7 @@ void SigInt( int ) void Usage() { - printf( "Usage: capture -o output.tracy [-a address] [-p port]\n" ); + printf( "Usage: capture -o output.tracy [-a address] [-p port] [-f]\n" ); exit( 1 ); } @@ -41,12 +42,13 @@ int main( int argc, char** argv ) } #endif + bool overwrite = false; const char* address = "localhost"; const char* output = nullptr; int port = 8086; int c; - while( ( c = getopt( argc, argv, "a:o:p:" ) ) != -1 ) + while( ( c = getopt( argc, argv, "a:o:p:f" ) ) != -1 ) { switch( c ) { @@ -59,6 +61,9 @@ int main( int argc, char** argv ) case 'p': port = atoi( optarg ); break; + case 'f': + overwrite = true; + break; default: Usage(); break; @@ -67,6 +72,13 @@ int main( int argc, char** argv ) if( !address || !output ) Usage(); + struct stat st; + if( stat( output, &st ) == 0 && !overwrite ) + { + printf( "Output file %s already exists! Use -f to force overwrite.\n", output ); + return 4; + } + printf( "Connecting to %s:%i...", address, port ); fflush( stdout ); tracy::Worker worker( address, port ); |