--- pbx/pbx_spool.c.orig 2006-03-22 09:04:40.000000000 -0600 +++ pbx/pbx_spool.c 2006-03-22 09:04:21.000000000 -0600 @@ -255,6 +255,9 @@ { struct outgoing *o = data; int res, reason; + struct stat current_file_status; + int delete_call_file = 1; + time_t end_time; if (!ast_strlen_zero(o->app)) { if (option_verbose > 2) ast_verbose(VERBOSE_PREFIX_3 "Attempting call on %s/%s for application %s(%s) (Retry %d)\n", o->tech, o->dest, o->app, o->data, o->retries); @@ -277,7 +280,20 @@ } else { ast_log(LOG_NOTICE, "Call completed to %s/%s\n", o->tech, o->dest); ast_log(LOG_EVENT, "Queued call to %s/%s completed\n", o->tech, o->dest); - unlink(o->fn); + if ( !stat(o->fn, ¤t_file_status) ) { + time(&end_time); + if ( end_time < current_file_status.st_atime ) { + ast_log(LOG_DEBUG, "call file stat date has changed to the future, keeping file\n"); + delete_call_file = 0; + } else { + ast_log(LOG_DEBUG, "deleting call file\n"); + } + } else { + ast_log(LOG_WARNING, "Unable to stat %s, possibly deleting a valid call file\n", o->fn); + } + if ( delete_call_file ) { + unlink(o->fn); + } } free_outgoing(o); return NULL;