Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mpv-player/mpv
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 35737cbef4f464429552f448a6cef06f26aca9b2
Choose a base ref
..
head repository: mpv-player/mpv
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 637981e957f6300f8bc6dd934f5483877874669d
Choose a head ref
Showing with 23 additions and 4 deletions.
  1. +23 −4 player/loadfile.c
27 changes: 23 additions & 4 deletions player/loadfile.c
Original file line number Diff line number Diff line change
@@ -1534,7 +1534,7 @@ static void append_to_watch_history(struct MPContext *mpctx)
FILE *history_file = fopen(history_path, "ab");

if (!history_file) {
MP_ERR(mpctx, "Failed to write to %s: %s\n", history_path,
MP_ERR(mpctx, "Failed to open history file: %s\n",
mp_strerror(errno));
goto done;
}
@@ -1571,12 +1571,31 @@ static void append_to_watch_history(struct MPContext *mpctx)
json_write(&dst, &node);
dst = talloc_strdup_append(dst, "\n");

bool failed = fwrite(dst, strlen(dst), 1, history_file) != 1;
if (fclose(history_file) || failed) {
MP_ERR(mpctx, "Failed to write to %s: %s\n", history_path,
long history_size = ftell(history_file);
if (history_size == -1) {
MP_ERR(mpctx, "Failed to get history file size: %s\n",
mp_strerror(errno));
fclose(history_file);
goto done;
}

bool failed = fwrite(dst, strlen(dst), 1, history_file) != 1 &&
fflush(history_file) != 0;

if (failed) {
MP_ERR(mpctx, "Failed to write to history file: %s\n",
mp_strerror(errno));

int fd = fileno(history_file);
if (fd == -1 || ftruncate(fd, history_size) == -1)
MP_ERR(mpctx, "Failed to roll-back history file: %s\n",
mp_strerror(errno));
}

if (fclose(history_file) != 0)
MP_ERR(mpctx, "Failed to close history file: %s\n",
mp_strerror(errno));

done:
talloc_free(ctx);
}