Clean up the file saving code a bit.
svn path=/trunk/; revision=5531
This commit is contained in:
parent
c01a2aa70b
commit
a6a5ff53ea
102
file.c
102
file.c
|
@ -1,7 +1,7 @@
|
||||||
/* file.c
|
/* file.c
|
||||||
* File I/O routines
|
* 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
|
* Ethereal - Network traffic analyzer
|
||||||
* By Gerald Combs <gerald@ethereal.com>
|
* By Gerald Combs <gerald@ethereal.com>
|
||||||
|
@ -1724,7 +1724,6 @@ gboolean
|
||||||
save_cap_file(char *fname, capture_file *cf, gboolean save_filtered,
|
save_cap_file(char *fname, capture_file *cf, gboolean save_filtered,
|
||||||
gboolean save_marked, guint save_format)
|
gboolean save_marked, guint save_format)
|
||||||
{
|
{
|
||||||
gboolean ret = TRUE;
|
|
||||||
gchar *from_filename;
|
gchar *from_filename;
|
||||||
gchar *name_ptr, *save_msg, *save_fmt = " Saving: %s...";
|
gchar *name_ptr, *save_msg, *save_fmt = " Saving: %s...";
|
||||||
size_t msg_len;
|
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?) */
|
is it worth requiring the user to go off and fix it?) */
|
||||||
simple_dialog(ESD_TYPE_CRIT, NULL,
|
simple_dialog(ESD_TYPE_CRIT, NULL,
|
||||||
file_rename_error_message(errno), fname);
|
file_rename_error_message(errno), fname);
|
||||||
ret = FALSE;
|
goto fail;
|
||||||
goto done;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -1793,15 +1791,12 @@ save_cap_file(char *fname, capture_file *cf, gboolean save_filtered,
|
||||||
simple_dialog(ESD_TYPE_CRIT, NULL,
|
simple_dialog(ESD_TYPE_CRIT, NULL,
|
||||||
"Can't save over current capture file: %s!",
|
"Can't save over current capture file: %s!",
|
||||||
from_filename);
|
from_filename);
|
||||||
ret = FALSE;
|
goto fail;
|
||||||
goto done;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy the file, if we haven't moved it. */
|
/* Copy the file, if we haven't moved it. */
|
||||||
if (!copy_binary_file(from_filename, fname)) {
|
if (!copy_binary_file(from_filename, fname))
|
||||||
ret = FALSE;
|
goto fail;
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Either we're filtering packets, or we're saving in a different
|
/* 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) {
|
if (pdh == NULL) {
|
||||||
simple_dialog(ESD_TYPE_CRIT, NULL,
|
simple_dialog(ESD_TYPE_CRIT, NULL,
|
||||||
file_open_error_message(err, TRUE), fname);
|
file_open_error_message(err, TRUE), fname);
|
||||||
ret = FALSE;
|
goto fail;
|
||||||
goto done;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XXX - have a way to save only the packets currently selected by
|
/* XXX - have a way to save only the packets currently selected by
|
||||||
|
@ -1841,19 +1835,17 @@ save_cap_file(char *fname, capture_file *cf, gboolean save_filtered,
|
||||||
hdr.pkt_encap = fdata->lnk_t;
|
hdr.pkt_encap = fdata->lnk_t;
|
||||||
if (!wtap_seek_read(cf->wth, fdata->file_off, &pseudo_header,
|
if (!wtap_seek_read(cf->wth, fdata->file_off, &pseudo_header,
|
||||||
pd, fdata->cap_len, &err)) {
|
pd, fdata->cap_len, &err)) {
|
||||||
simple_dialog(ESD_TYPE_CRIT, NULL,
|
simple_dialog(ESD_TYPE_CRIT, NULL,
|
||||||
file_read_error_message(err), cf->filename);
|
file_read_error_message(err), cf->filename);
|
||||||
wtap_dump_close(pdh, &err);
|
wtap_dump_close(pdh, &err);
|
||||||
ret = FALSE;
|
goto fail;
|
||||||
goto done;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!wtap_dump(pdh, &hdr, &pseudo_header, pd, &err)) {
|
if (!wtap_dump(pdh, &hdr, &pseudo_header, pd, &err)) {
|
||||||
simple_dialog(ESD_TYPE_CRIT, NULL,
|
simple_dialog(ESD_TYPE_CRIT, NULL,
|
||||||
file_write_error_message(err), fname);
|
file_write_error_message(err), fname);
|
||||||
wtap_dump_close(pdh, &err);
|
wtap_dump_close(pdh, &err);
|
||||||
ret = FALSE;
|
goto fail;
|
||||||
goto done;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1861,53 +1853,53 @@ save_cap_file(char *fname, capture_file *cf, gboolean save_filtered,
|
||||||
if (!wtap_dump_close(pdh, &err)) {
|
if (!wtap_dump_close(pdh, &err)) {
|
||||||
simple_dialog(ESD_TYPE_WARN, NULL,
|
simple_dialog(ESD_TYPE_WARN, NULL,
|
||||||
file_close_error_message(err), fname);
|
file_close_error_message(err), fname);
|
||||||
ret = FALSE;
|
goto fail;
|
||||||
goto done;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
|
||||||
|
|
||||||
/* Pop the "Saving:" message off the status bar. */
|
/* Pop the "Saving:" message off the status bar. */
|
||||||
statusbar_pop_file_msg();
|
statusbar_pop_file_msg();
|
||||||
if (ret) {
|
if (!save_filtered && !save_marked) {
|
||||||
if (!save_filtered && !save_marked) {
|
/* We saved the entire capture, not just some packets from it.
|
||||||
/* We saved the entire capture, not just some packets from it.
|
Open and read the file we saved it to.
|
||||||
Open and read the file we saved it to.
|
|
||||||
|
|
||||||
XXX - this is somewhat of a waste; we already have the
|
XXX - this is somewhat of a waste; we already have the
|
||||||
packets, all this gets us is updated file type information
|
packets, all this gets us is updated file type information
|
||||||
(which we could just stuff into "cf"), and having the new
|
(which we could just stuff into "cf"), and having the new
|
||||||
file be the one we have opened and from which we're reading
|
file be the one we have opened and from which we're reading
|
||||||
the data, and it means we have to spend time opening and
|
the data, and it means we have to spend time opening and
|
||||||
reading the file, which could be a significant amount of
|
reading the file, which could be a significant amount of
|
||||||
time if the file is large. */
|
time if the file is large. */
|
||||||
cf->user_saved = TRUE;
|
cf->user_saved = TRUE;
|
||||||
|
|
||||||
if ((err = open_cap_file(fname, FALSE, cf)) == 0) {
|
if ((err = open_cap_file(fname, FALSE, cf)) == 0) {
|
||||||
/* XXX - report errors if this fails? */
|
/* XXX - report errors if this fails?
|
||||||
switch (read_cap_file(cf, &err)) {
|
What should we return if it fails or is aborted? */
|
||||||
|
switch (read_cap_file(cf, &err)) {
|
||||||
|
|
||||||
case READ_SUCCESS:
|
case READ_SUCCESS:
|
||||||
case READ_ERROR:
|
case READ_ERROR:
|
||||||
/* Just because we got an error, that doesn't mean we were unable
|
/* Just because we got an error, that doesn't mean we were unable
|
||||||
to read any of the file; we handle what we could get from the
|
to read any of the file; we handle what we could get from the
|
||||||
file. */
|
file. */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case READ_ABORTED:
|
case READ_ABORTED:
|
||||||
/* The user bailed out of re-reading the capture file; the
|
/* The user bailed out of re-reading the capture file; the
|
||||||
capture file has been closed - just return (without
|
capture file has been closed - just return (without
|
||||||
changing any menu settings; "close_cap_file()" set them
|
changing any menu settings; "close_cap_file()" set them
|
||||||
correctly for the "no capture file open" state). */
|
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 */
|
|
||||||
}
|
}
|
||||||
|
set_menus_for_unsaved_capture_file(FALSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return TRUE;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
/* Pop the "Saving:" message off the status bar. */
|
||||||
|
statusbar_pop_file_msg();
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
|
|
Loading…
Reference in New Issue