Browse Source

make path expansion match docu: paths are relative to ~

the current behavior of being relative to the current directory sort of
makes no sense, and contradicts the docu.
(cherry picked from commit da5ce5d8f4)
1.0
Oswald Buddenhagen 12 years ago
parent
commit
c07eb05e61
  1. 2
      src/config.c
  2. 15
      src/util.c

2
src/config.c

@ -163,7 +163,7 @@ getopt_helper( conffile_t *cfile, int *cops, int *mops, int *sops, char **sync_s
while ((arg = next_arg( &cfile->rest ))); while ((arg = next_arg( &cfile->rest )));
*mops |= XOP_HAVE_CREATE; *mops |= XOP_HAVE_CREATE;
} else if (!strcasecmp( "SyncState", cfile->cmd )) } else if (!strcasecmp( "SyncState", cfile->cmd ))
*sync_state = expand_strdup( cfile->val ); *sync_state = !strcmp( cfile->val, "*" ) ? nfstrdup( "*" ) : expand_strdup( cfile->val );
else else
return 0; return 0;
return 1; return 1;

15
src/util.c

@ -303,24 +303,35 @@ expand_strdup( const char *s )
if (*s == '~') { if (*s == '~') {
s++; s++;
if (!*s) { if (!*s) {
rethome:
p = 0; p = 0;
q = Home; q = Home;
} else if (*s == '/') { } else if (*s == '/') {
p = s; p = s + 1;
q = Home; q = Home;
} else { } else {
if ((p = strchr( s, '/' ))) { if ((p = strchr( s, '/' ))) {
r = my_strndup( s, (int)(p - s) ); r = my_strndup( s, (int)(p - s) );
pw = getpwnam( r ); pw = getpwnam( r );
free( r ); free( r );
p++;
} else } else
pw = getpwnam( s ); pw = getpwnam( s );
if (!pw) if (!pw)
return 0; return 0;
q = pw->pw_dir; q = pw->pw_dir;
} }
nfasprintf( &r, "%s%s", q, p ? p : "" ); if (!p)
return nfstrdup( q );
retjoin:
nfasprintf( &r, "%s/%s", q, p );
return r; return r;
} else if (*s != '/') {
if (*s == '.' && !s[1])
goto rethome;
p = s;
q = Home;
goto retjoin;
} else } else
return nfstrdup( s ); return nfstrdup( s );
} }

Loading…
Cancel
Save