]> git.ipfire.org Git - thirdparty/git.git/commit - builtin/gc.c
gc: use temporary file for editing crontab
authorbrian m. carlson <sandals@crustytoothpaste.net>
Sun, 28 Aug 2022 21:41:43 +0000 (21:41 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sun, 28 Aug 2022 22:47:00 +0000 (15:47 -0700)
commitee69e7884e0cae3d2feabd5fcce8d3dfb44dda3a
tree1191f6d73ff34401df8f44b9a4135f03944e5d9d
parent0f5bd024f21b3700ce37148d75ad7918bf9977f8
gc: use temporary file for editing crontab

While cron is specified by POSIX, there are a wide variety of
implementations in use.  "git maintenance" assumes that the
"crontab" command can be fed from its standard input the new
contents and the syntax to do so is not to have any filename
argument, as POSIX describes.  However, on FreeBSD, the cron
implementation requires a file name argument: if the user wants to
edit standard input, they must specify "-".

Unfortunately, POSIX systems do not have to interpret "-" on the
command line of crontab as a request to read from the standard
input.  Blindly adding "-" on the command line would not work as a
general solution.

Since POSIX tells us that cron must accept a file name argument, let's
solve this problem by specifying a temporary file instead.  This will
ensure that we work with the vast majority of implementations.

Note that because delete_tempfile closes the file for us, we should not
call fclose here on the handle, since doing so will introduce a double
free.

Reported-by: Renato Botelho <garga@FreeBSD.org>
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/gc.c
t/helper/test-crontab.c