Commit e1178a7a authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

bug fix if table filename is a directory [Bug #5891]

parent 67b1cae5
......@@ -3,6 +3,10 @@
* using CDI library version 1.7.0
* Version 1.7.0 released
2015-06-17 Uwe Schulzweida
* bug fix if table filename is a directory [Bug #5891]
2015-06-12 Uwe Schulzweida
* diff: disable checkrel
......
......@@ -13,6 +13,7 @@ Version 1.7.0 (28 October 2015):
Changed operators:
* vertvar, vertstd: changed to weighted var/std if layer bounds are available
Fixed bugs:
* cdo -t table_file does not complain if table_file is a directory [Bug #5891]
* expr: operators return 0 for arithmetics on constants [Bug #5875]
* env. CDO_TIMESTAT_DATE does not work [Bug #5758]
* splityear*: support for constant fields is missing [Bug #5759]
......
......@@ -318,7 +318,7 @@ void read_partab(pt_mode_t ptmode, int nvars, int vlistID2, var_t *vars)
for ( int fileID = 0; fileID < num_pt_files; ++fileID )
{
partab = operatorArgv()[fileID];
fp = fopen(partab, "r");
if ( fileExists(partab) ) fp = fopen(partab, "r");
if ( fp == NULL ) cdoAbort("Open failed on parameter table %d file name %s!", fileID+1, partab);
nml_index = 0;
......@@ -637,7 +637,8 @@ void *Setpartab(void *argument)
if ( ptmode == CODE_NUMBER )
{
char *partab = operatorArgv()[0];
FILE *fp = fopen(partab, "r");
FILE *fp = NULL;
if ( fileExists(partab) ) fp = fopen(partab, "r");
if ( fp != NULL )
{
fseek(fp, 0L, SEEK_END);
......
......@@ -142,7 +142,8 @@ void job_submit(const char *expname, const char *jobfilename, const char *jobnam
void minmaxval(long nvals, double *array, int *imiss, double *minval, double *maxval);
off_t filesize(const char *filename);
FILE *fopen_read(const char *restrict filename);
off_t filesize(const char *restrict filename);
char *expand_filename(const char *string);
......
......@@ -25,21 +25,15 @@
#include "error.h"
#ifndef UNDEFID
#define UNDEFID CDI_UNDEFID
#endif
int defineTable(char *tablearg)
{
char *tablename;
int tableID = UNDEFID;
int tableID = CDI_UNDEFID;
tablename = tablearg;
char *tablename = tablearg;
tableID = tableRead(tablename);
if ( fileExists(tablename) ) tableID = tableRead(tablename);
if ( tableID == UNDEFID )
if ( tableID == CDI_UNDEFID )
{
char *tablepath = getenv("CD_TABLEPATH");
......@@ -51,15 +45,15 @@ int defineTable(char *tablearg)
strcpy(tablefile, tablepath);
strcat(tablefile, "/");
strcat(tablefile, tablename);
tableID = tableRead(tablefile);
if ( fileExists(tablename) ) tableID = tableRead(tablefile);
free(tablefile);
}
}
if ( tableID == UNDEFID )
if ( tableID == CDI_UNDEFID )
tableID = tableInq(-1, 0, tablename);
if ( tableID == UNDEFID )
if ( tableID == CDI_UNDEFID )
Error("table <%s> not found", tablename);
return (tableID);
......
......@@ -478,21 +478,21 @@ int month_to_season(int month)
#include <sys/stat.h>
//#include <unistd.h>
int fileExists(const char *filename)
int fileExists(const char *restrict filename)
{
int status = 0;
struct stat buf;
if ( stat(filename, &buf) == 0 )
{
if ( buf.st_size > 0 ) status = 1;
if ( S_ISREG(buf.st_mode) && buf.st_size > 0 ) status = 1;
}
return (status);
return status;
}
int userFileOverwrite(const char *filename)
int userFileOverwrite(const char *restrict filename)
{
int status = 0, len;
char line[1024], *pline;
......@@ -622,9 +622,8 @@ int str2datatype(const char *datatypestr)
}
off_t filesize(const char *filename)
off_t filesize(const char *restrict filename)
{
FILE *fp;
off_t pos = 0;
if ( filename[0] == '(' && filename[1] == 'p' )
......@@ -632,6 +631,7 @@ off_t filesize(const char *filename)
}
else
{
FILE *fp = NULL;
fp = fopen(filename, "r");
if ( fp == NULL )
{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment