1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-04-27 23:45:12 +02:00

tempfile: factor out activation

There are a few steps required to "activate" a tempfile
struct. Let's pull these out into a function. That saves a
few repeated lines now, but more importantly will make it
easier to change the activation scheme later.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff King 2017-09-05 08:14:47 -04:00 committed by Junio C Hamano
parent 9b028aa45a
commit 2933ebbac1

View File

@ -113,6 +113,12 @@ static void prepare_tempfile_object(struct tempfile *tempfile)
}
}
static void activate_tempfile(struct tempfile *tempfile)
{
tempfile->owner = getpid();
tempfile->active = 1;
}
/* Make sure errno contains a meaningful value on error */
int create_tempfile(struct tempfile *tempfile, const char *path)
{
@ -129,8 +135,7 @@ int create_tempfile(struct tempfile *tempfile, const char *path)
strbuf_reset(&tempfile->filename);
return -1;
}
tempfile->owner = getpid();
tempfile->active = 1;
activate_tempfile(tempfile);
if (adjust_shared_perm(tempfile->filename.buf)) {
int save_errno = errno;
error("cannot fix permission bits on %s", tempfile->filename.buf);
@ -145,8 +150,7 @@ void register_tempfile(struct tempfile *tempfile, const char *path)
{
prepare_tempfile_object(tempfile);
strbuf_add_absolute_path(&tempfile->filename, path);
tempfile->owner = getpid();
tempfile->active = 1;
activate_tempfile(tempfile);
}
int mks_tempfile_sm(struct tempfile *tempfile,
@ -160,8 +164,7 @@ int mks_tempfile_sm(struct tempfile *tempfile,
strbuf_reset(&tempfile->filename);
return -1;
}
tempfile->owner = getpid();
tempfile->active = 1;
activate_tempfile(tempfile);
return tempfile->fd;
}
@ -182,8 +185,7 @@ int mks_tempfile_tsm(struct tempfile *tempfile,
strbuf_reset(&tempfile->filename);
return -1;
}
tempfile->owner = getpid();
tempfile->active = 1;
activate_tempfile(tempfile);
return tempfile->fd;
}