Browse Source

MT#61977 move unlinking to output_close

Return success indicator from db_close_stream and use that to decide
whether to unlink the file. If DB storage failed then we can retain the
recording on file.

Change-Id: I91520f0ded223965a7a9cb1f200b8af06f555427
pull/1998/head
Richard Fuchs 4 months ago
parent
commit
b2837eddbc
3 changed files with 26 additions and 23 deletions
  1. +15
    -18
      recording-daemon/db.c
  2. +1
    -1
      recording-daemon/db.h
  3. +10
    -4
      recording-daemon/output.c

+ 15
- 18
recording-daemon/db.c View File

@ -375,17 +375,18 @@ void db_close_call(metafile_t *mf) {
}
}
void db_close_stream(output_t *op, FILE *fp, GString *gs) {
bool db_close_stream(output_t *op, FILE *fp, GString *gs) {
if (check_conn() || op->db_id == 0) {
if (fp)
fclose(fp);
return;
return !(output_storage & OUTPUT_STORAGE_DB); // error if DB storage is requested
}
int64_t now = now_us();
str stream = STR_NULL;
MYSQL_BIND b[3];
bool ok = false;
if ((output_storage & OUTPUT_STORAGE_DB)) {
if (gs) {
@ -400,18 +401,14 @@ void db_close_stream(output_t *op, FILE *fp, GString *gs) {
f = fopen(op->filename, "rb");
if (!f) {
ilog(LOG_ERR, "Failed to open file: %s%s%s", FMT_M(op->filename));
if ((output_storage & OUTPUT_STORAGE_FILE))
goto file;
return;
goto entry;
}
fseek(f, 0, SEEK_END);
long pos = ftell(f);
if (pos < 0) {
ilog(LOG_ERR, "Failed to get file position: %s", strerror(errno));
fclose(f);
if ((output_storage & OUTPUT_STORAGE_FILE))
goto file;
return;
goto entry;
}
stream.len = pos;
fseek(f, 0, SEEK_SET);
@ -422,19 +419,20 @@ void db_close_stream(output_t *op, FILE *fp, GString *gs) {
stream.len = 0;
ilog(LOG_ERR, "Failed to read from stream");
fclose(f);
if ((output_storage & OUTPUT_STORAGE_FILE))
goto file;
g_free(stream.s);
return;
goto entry;
}
}
ok = true;
fclose(f);
}
}
else if (fp)
fclose(fp);
else {
ok = true;
if (fp)
fclose(fp);
}
file:;
entry:;
int par_idx = 0;
double ts;
my_ts(&b[par_idx++], now, &ts);
@ -445,9 +443,8 @@ file:;
execute_wrap(&stm_close_stream, b, NULL);
g_free(stream.s);
if (op->filename && !(output_storage & OUTPUT_STORAGE_FILE))
if (unlink(op->filename))
ilog(LOG_ERR, "Failed to delete file '%s': %s", op->filename, strerror(errno));
return ok;
}
void db_delete_stream(metafile_t *mf, output_t *op) {


+ 1
- 1
recording-daemon/db.h View File

@ -7,7 +7,7 @@
void db_do_call(metafile_t *);
void db_close_call(metafile_t *);
void db_do_stream(metafile_t *mf, output_t *op, stream_t *, unsigned long ssrc);
void db_close_stream(output_t *op, FILE *, GString *);
bool db_close_stream(output_t *op, FILE *, GString *);
void db_delete_stream(metafile_t *, output_t *op);
void db_config_stream(output_t *op);
void db_thread_end(void);


+ 10
- 4
recording-daemon/output.c View File

@ -578,11 +578,13 @@ void sink_close(sink_t *sink) {
void output_close(metafile_t *mf, output_t *output, tag_t *tag, bool discard) {
if (!output)
return;
bool do_delete = !(output_storage & OUTPUT_STORAGE_FILE);
if (!discard) {
GString *membuf = NULL;
FILE *fp = NULL;
if (output_shutdown(output, &fp, &membuf)) {
db_close_stream(output, fp, membuf);
if (!db_close_stream(output, fp, membuf))
do_delete = false;
notify_push_output(output, mf, tag);
}
else {
@ -593,12 +595,16 @@ void output_close(metafile_t *mf, output_t *output, tag_t *tag, bool discard) {
}
else {
output_shutdown(output, NULL, NULL);
if (output->filename && unlink(output->filename))
ilog(LOG_WARN, "Failed to unlink '%s%s%s': %s",
FMT_M(output->filename), strerror(errno));
do_delete = true;
db_delete_stream(mf, output);
}
encoder_free(output->encoder);
if (output->filename && do_delete) {
if (unlink(output->filename))
ilog(LOG_ERR, "Failed to delete file '%s%s%s': %s",
FMT_M(output->filename), strerror(errno));
}
g_clear_pointer(&output->full_filename, g_free);
g_clear_pointer(&output->file_path, g_free);
g_clear_pointer(&output->file_name, g_free);


Loading…
Cancel
Save