From b655197a9dbfc5ea973ffa37b9642de0c1baeec1 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Thu, 24 May 2012 02:16:53 +0000 Subject: In the "Save As" and "Export Specified Packets" code path, do a "safe save" if the destination file exists. Don't forbid overwriting an existing file in either of those cases (we still forbid overwriting the current capture file) - the GUI asks the user whether they want to do the overwrite, and allows them to cancel out of it - and don't remove the file before writing to it (doing so makes the save *un*safe). Attempt to do a save of an unedited temporary file by just moving the file on Windows as well as on UN*X - ws_rename() will remove the target if necessary on Windows (and won't do it as a separate operation before attempting the rename), so it behaves like ws_rename() on UN*X (which is just a wrapper around rename()). svn path=/trunk/; revision=42816 --- file.h | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'file.h') diff --git a/file.h b/file.h index ea6b908e90..c136e2fc2f 100644 --- a/file.h +++ b/file.h @@ -118,7 +118,7 @@ void cf_reload(capture_file *cf); * Read all packets of a capture file into the internal structures. * * @param cf the capture file to be read - * @param from_save reread asked from cf_save + * @param from_save reread asked from cf_save_packets * @return one of cf_read_status_t */ cf_read_status_t cf_read(capture_file *cf, gboolean from_save); @@ -195,22 +195,12 @@ cf_read_status_t cf_finish_tail(capture_file *cf, int *err); */ gboolean cf_can_save_as(capture_file *cf); -/** - * Save a capture file. Does a "safe save" if the specified - * pathname already exists. - * - * @param cf the capture file to save to - * @param fname the filename to save to - * @param save_format the format of the file to save (libpcap, ...) - * @param compressed whether to gzip compress the file - * @return one of cf_status_t - */ -cf_status_t cf_save(capture_file * cf, const char *fname, guint save_format, gboolean compressed); - /** * Save all packets in a capture file to a new file, and, if that succeeds, - * make that file the current capture file. Fails if the specified - * target file already exists. + * make that file the current capture file. If there's already a file with + * that name, do a "safe save", writing to a temporary file in the same + * directory and, if the write succeeds, renaming the new file on top of the + * old file, so that if the write fails, the old file is still intact. * * @param cf the capture file to save to * @param fname the filename to save to @@ -218,11 +208,14 @@ cf_status_t cf_save(capture_file * cf, const char *fname, guint save_format, gbo * @param compressed whether to gzip compress the file * @return one of cf_status_t */ -cf_status_t cf_save_as(capture_file * cf, const char *fname, guint save_format, gboolean compressed); +cf_status_t cf_save_packets(capture_file * cf, const char *fname, guint save_format, gboolean compressed); /** - * Export some or all packets from a capture file to a new file. Fails if - * the specified target file already exists. + * Export some or all packets from a capture file to a new file. If there's + * already a file with that name, do a "safe save", writing to a temporary + * file in the same directory and, if the write succeeds, renaming the new + * file on top of the old file, so that if the write fails, the old file is + * still intact. * * @param cf the capture file to write to * @param fname the filename to write to -- cgit v1.2.1