|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
Don't overwrite the output fileDon't overwrite the output file
In case the output file specified via -F already exists, it is overwritten without a hint to the user. The patch changes the behavior so that an output file is never touched if it is already writeable. --- Alternative: Rename the existing file to filename~. Shortcomings: The program aborts late - the whole input data is read from fname before the check is executed. The realize a early check, the main() function has to be redesigned to first read _all_ options before anything is read from fname. Please tell me if such a rearranging is appreciated. diff --git a/main.c b/main.c index 778d687..6b4195e 100644 --- a/main.c +++ b/main.c @@ -218,6 +218,21 @@ print_extended_info(void) "\n"); } +/** + * @return 1 if file exits and is writeable, otherwise 0 + */ +static int +file_writeable(const char *filename) +{ + FILE *f = fopen(filename, "w"); + int retval = f != NULL; + + if (f != NULL) + fclose(f); + + return retval; +} + int main(int argc, char *argv[]) { @@ -373,6 +388,12 @@ main(int argc, char *argv[]) if (ofname == NULL) { fatal ("No output file or device name specified.\n"); } + + if (file_writeable(ofname)) + { + fatal ("Output file already exists.\n"); + } + if (ovecs && (!(global_opts.masked_objective & POSNDATAMASK))) { /* simulates the default behaviour of waypoints */ if (doing_nothing) ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Gpsbabel-code mailing list http://www.gpsbabel.org Gpsbabel-code@... https://lists.sourceforge.net/lists/listinfo/gpsbabel-code |
|
|
Re: Don't overwrite the output fileHello,
The code won't work as it is. The mere act of fopen(..., "w") will have overwritten the file and truncated it. There are are other ways of testing what you want. On the other hand, for a command lline execution, it is normal and expected behavior to ovewrite existing files. On Thu, Sep 10, 2009 at 5:55 PM, Stefan Bauer <yoltia-maintain@...> wrote: Don't overwrite the output file ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Gpsbabel-code mailing list http://www.gpsbabel.org Gpsbabel-code@... https://lists.sourceforge.net/lists/listinfo/gpsbabel-code |
|
|
|
|
|
Re: Don't overwrite the output fileOn 11 Sep 2009, at 00:06, Stefan Bauer wrote:
> I ran into this issue as today I accidently was about to overwrite > the track I > downloaded the day before just because of reusing the complete > command line > from history. > There ary many command line tools where overwriting must be forced. It's still the exception rather than the rule and changing the behaviour of gpsbabel in this way will break extant scripts that rely on the old behaviour. If you want to make sure it can't happen by accident put [ -e out.gpx ] || gpsbabel ... -F out.kpx in your command line history. -- Andy Armstrong, Hexten ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Gpsbabel-code mailing list http://www.gpsbabel.org Gpsbabel-code@... https://lists.sourceforge.net/lists/listinfo/gpsbabel-code |
| Free embeddable forum powered by Nabble | Forum Help |