1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-02 22:46:30 +02:00

g13: Re-factor high level create code.

* g13/create.c (g13_create_container): Factor some code out to ...
* g13/backend.c (be_take_lock_for_create): new.

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2016-02-02 09:03:37 +01:00
parent 3087197008
commit dc1dbc43a6
No known key found for this signature in database
GPG key ID: E3FDFF218E45B72B
3 changed files with 64 additions and 28 deletions

View file

@ -239,35 +239,10 @@ g13_create_container (ctrl_t ctrl, const char *filename, strlist_t keys)
if (!keys)
return gpg_error (GPG_ERR_NO_PUBKEY);
/* A quick check to see that no container with that name already
exists. */
if (!access (filename, F_OK))
return gpg_error (GPG_ERR_EEXIST);
err = be_take_lock_for_create (ctrl, filename, &lock);
if (err)
goto leave;
/* Take a lock and proceed with the creation. If there is a lock we
immediately return an error because for creation it does not make
sense to wait. */
lock = dotlock_create (filename, 0);
if (!lock)
return gpg_error_from_syserror ();
if (dotlock_take (lock, 0))
{
err = gpg_error_from_syserror ();
goto leave;
}
else
err = 0;
/* Check again that the file does not exist. */
{
struct stat sb;
if (!stat (filename, &sb))
{
err = gpg_error (GPG_ERR_EEXIST);
goto leave;
}
}
/* And a possible detached file or directory may not exist either. */
err = be_get_detached_name (ctrl->conttype, filename,
&detachedname, &detachedisdir);