Browse Source

create sync state parent directories recursively

this may matter with SyncState being for example ~/.local/state/isync/.
wip/maildir-path-under-inbox
Oswald Buddenhagen 3 years ago
parent
commit
8bb679ea06
  1. 2
      src/common.h
  2. 17
      src/drv_maildir.c
  3. 2
      src/sync_state.c
  4. 16
      src/util.c

2
src/common.h

@ -186,6 +186,8 @@ void ATTR_NORETURN oom( void );
int map_name( const char *arg, char **result, uint reserve, const char *in, const char *out );
int mkdir_p( char *path, int len );
#define DEFINE_ARRAY_TYPE(T) \
typedef struct { \
T *data; \

17
src/drv_maildir.c

@ -563,21 +563,6 @@ maildir_clear_tmp( char *buf, int bufsz, int bl )
return DRV_OK;
}
static int
make_box_dir( char *buf, int bl )
{
char *p;
if (!mkdir( buf, 0700 ) || errno == EEXIST)
return 0;
p = memrchr( buf, '/', (size_t)bl - 1 );
*p = 0;
if (make_box_dir( buf, (int)(p - buf) ))
return -1;
*p = '/';
return mkdir( buf, 0700 );
}
static int
maildir_validate( const char *box, int create, maildir_store_t *ctx )
{
@ -593,7 +578,7 @@ maildir_validate( const char *box, int create, maildir_store_t *ctx )
}
if (!create)
return DRV_BOX_BAD;
if (make_box_dir( buf, bl )) {
if (mkdir_p( buf, bl - 1 )) {
sys_error( "Maildir error: cannot create mailbox '%s'", buf );
ctx->conf->failed = FAIL_FINAL;
maildir_invoke_bad_callback( ctx );

2
src/sync_state.c

@ -58,7 +58,7 @@ prepare_state( sync_vars_t *svars )
// Note that this may be shorter than the configuration value,
// as that may contain a filename prefix.
*s = 0;
if (mkdir( svars->dname, 0700 ) && errno != EEXIST) {
if (mkdir_p( svars->dname, s - svars->dname )) {
sys_error( "Error: cannot create SyncState directory '%s'", svars->dname );
return 0;
}

16
src/util.c

@ -8,6 +8,7 @@
#include "common.h"
#include <fcntl.h>
#include <sys/stat.h>
#include <errno.h>
#include <ctype.h>
#include <pwd.h>
@ -539,6 +540,21 @@ map_name( const char *arg, char **result, uint reserve, const char *in, const ch
return 0;
}
int
mkdir_p( char *path, int len )
{
if (!mkdir( path, 0700 ) || errno == EEXIST)
return 0;
char *p = memrchr( path, '/', (size_t)len );
*p = 0;
if (mkdir_p( path, (int)(p - path) )) {
*p = '/';
return -1;
}
*p = '/';
return mkdir( path, 0700 );
}
static int
compare_uints( const void *l, const void *r )
{

Loading…
Cancel
Save