Skip to content

Commit

Permalink
Exit with an error if an empty file is opened from the command line.
Browse files Browse the repository at this point in the history
The old behaviour was to crash.
  • Loading branch information
netterfield committed Jul 8, 2021
1 parent 50b5995 commit a66bbde
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
4 changes: 0 additions & 4 deletions devel-docs/BugsAndFeatures
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ Icons are very small by default in UHD ubuntu 20.04

--------------

kst seems to crash with zero sized data files.

------------

Save a kst session. File dialog recent files doesn't include ".kst" if it was
automatically added on save.

Expand Down
45 changes: 25 additions & 20 deletions src/libkstapp/commandlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,21 @@ QString CommandLineParser::kstFileName() {
}
}

bool CommandLineParser::checkFile(QString filename) {
QFileInfo info(filename);
if (!info.exists()) {
printUsage(tr("file %1 does not exist.\n").arg(filename));
return false;
}
if (info.isFile()) {
if (info.size() == 0) {
printUsage(tr("file %1 is empty.\n").arg(filename));
return false;
}
}
return true;
}

bool CommandLineParser::processCommandLine(bool *ok) {
QString arg, param;
*ok=true;
Expand Down Expand Up @@ -520,10 +535,8 @@ bool CommandLineParser::processCommandLine(bool *ok) {
*ok = _setStringArg(_xField,tr("Usage: -x <xfieldname>\n"));
for (int i_file=0; i_file<_fileNames.size(); i_file++) {
QString file = _fileNames.at(i_file);
QFileInfo info(file);
if (!info.exists()) {
printUsage(tr("file %1 does not exist\n").arg(file));
*ok = false;
*ok = checkFile(file);
if (*ok == false) {
break;
}

Expand All @@ -547,10 +560,8 @@ bool CommandLineParser::processCommandLine(bool *ok) {
}
for (int i_file=0; i_file<_fileNames.size(); i_file++) {
QString file = _fileNames.at(i_file);
QFileInfo info(file);
if (!info.exists()) {
printUsage(tr("file %1 does not exist\n").arg(file));
*ok = false;
*ok = checkFile(file);
if (*ok == false) {
break;
}

Expand Down Expand Up @@ -601,10 +612,8 @@ bool CommandLineParser::processCommandLine(bool *ok) {
if (*ok) {
for (int i_file=0; i_file<_fileNames.size(); i_file++) {
QString file = _fileNames.at(i_file);
QFileInfo info(file);
if (!info.exists()) {
printUsage(tr("file %1 does not exist\n").arg(file));
*ok = false;
*ok = checkFile(file);
if (*ok == false) {
break;
}

Expand Down Expand Up @@ -650,10 +659,8 @@ bool CommandLineParser::processCommandLine(bool *ok) {
if (*ok) {
for ( int i_file=0; i_file<_fileNames.size(); i_file++ ) {
QString file = _fileNames.at ( i_file );
QFileInfo info ( file );
if ( !info.exists() || !info.isFile() ) {
printUsage ( tr ( "file %1 does not exist\n" ).arg ( file ) );
*ok = false;
*ok = checkFile(file);
if (*ok == false) {
break;
}

Expand Down Expand Up @@ -690,10 +697,8 @@ bool CommandLineParser::processCommandLine(bool *ok) {
if (*ok) {
for (int i_file=0; i_file<_fileNames.size(); i_file++) {
QString file = _fileNames.at(i_file);
QFileInfo info(file);
if (!info.exists() || !info.isFile()) {
printUsage(tr("file %1 does not exist\n").arg(file));
*ok = false;
*ok = checkFile(file);
if (*ok == false) {
break;
}

Expand Down
1 change: 1 addition & 0 deletions src/libkstapp/commandlineparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class CommandLineParser:QObject
~CommandLineParser();

bool processCommandLine(bool *ok);
bool checkFile(QString filename);
QString kstFileName();
QString pngFile() const {return _pngFile;}
int pngWidth() const {return _pngWidth;}
Expand Down

0 comments on commit a66bbde

Please sign in to comment.