Clean up the file saving code a bit.

svn path=/trunk/; revision=5531
This commit is contained in:
Guy Harris 2002-05-23 10:27:12 +00:00
parent c01a2aa70b
commit a6a5ff53ea
1 changed files with 47 additions and 55 deletions

44
file.c
View File

@ -1,7 +1,7 @@
/* file.c
* File I/O routines
*
* $Id: file.c,v 1.274 2002/05/23 07:46:58 guy Exp $
* $Id: file.c,v 1.275 2002/05/23 10:27:12 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -1724,7 +1724,6 @@ gboolean
save_cap_file(char *fname, capture_file *cf, gboolean save_filtered,
gboolean save_marked, guint save_format)
{
gboolean ret = TRUE;
gchar *from_filename;
gchar *name_ptr, *save_msg, *save_fmt = " Saving: %s...";
size_t msg_len;
@ -1772,8 +1771,7 @@ save_cap_file(char *fname, capture_file *cf, gboolean save_filtered,
is it worth requiring the user to go off and fix it?) */
simple_dialog(ESD_TYPE_CRIT, NULL,
file_rename_error_message(errno), fname);
ret = FALSE;
goto done;
goto fail;
}
}
#else
@ -1793,15 +1791,12 @@ save_cap_file(char *fname, capture_file *cf, gboolean save_filtered,
simple_dialog(ESD_TYPE_CRIT, NULL,
"Can't save over current capture file: %s!",
from_filename);
ret = FALSE;
goto done;
goto fail;
}
/* Copy the file, if we haven't moved it. */
if (!copy_binary_file(from_filename, fname)) {
ret = FALSE;
goto done;
}
if (!copy_binary_file(from_filename, fname))
goto fail;
}
} else {
/* Either we're filtering packets, or we're saving in a different
@ -1811,8 +1806,7 @@ save_cap_file(char *fname, capture_file *cf, gboolean save_filtered,
if (pdh == NULL) {
simple_dialog(ESD_TYPE_CRIT, NULL,
file_open_error_message(err, TRUE), fname);
ret = FALSE;
goto done;
goto fail;
}
/* XXX - have a way to save only the packets currently selected by
@ -1844,16 +1838,14 @@ save_cap_file(char *fname, capture_file *cf, gboolean save_filtered,
simple_dialog(ESD_TYPE_CRIT, NULL,
file_read_error_message(err), cf->filename);
wtap_dump_close(pdh, &err);
ret = FALSE;
goto done;
goto fail;
}
if (!wtap_dump(pdh, &hdr, &pseudo_header, pd, &err)) {
simple_dialog(ESD_TYPE_CRIT, NULL,
file_write_error_message(err), fname);
wtap_dump_close(pdh, &err);
ret = FALSE;
goto done;
goto fail;
}
}
}
@ -1861,16 +1853,12 @@ save_cap_file(char *fname, capture_file *cf, gboolean save_filtered,
if (!wtap_dump_close(pdh, &err)) {
simple_dialog(ESD_TYPE_WARN, NULL,
file_close_error_message(err), fname);
ret = FALSE;
goto done;
goto fail;
}
}
done:
/* Pop the "Saving:" message off the status bar. */
statusbar_pop_file_msg();
if (ret) {
if (!save_filtered && !save_marked) {
/* We saved the entire capture, not just some packets from it.
Open and read the file we saved it to.
@ -1885,7 +1873,8 @@ done:
cf->user_saved = TRUE;
if ((err = open_cap_file(fname, FALSE, cf)) == 0) {
/* XXX - report errors if this fails? */
/* XXX - report errors if this fails?
What should we return if it fails or is aborted? */
switch (read_cap_file(cf, &err)) {
case READ_SUCCESS:
@ -1900,14 +1889,17 @@ done:
capture file has been closed - just return (without
changing any menu settings; "close_cap_file()" set them
correctly for the "no capture file open" state). */
return 0;
break;
}
set_menus_for_unsaved_capture_file(FALSE);
ret = FALSE; /* XXX - save succeeded, but re-read failed */
}
}
}
return ret;
return TRUE;
fail:
/* Pop the "Saving:" message off the status bar. */
statusbar_pop_file_msg();
return FALSE;
}
char *