commit a7a575555390e37e68dc6249fa0b3881657e77d0
parent 2beb3256b2d087e23519b78cd87b3fb405705d98
Author: Christoph Lohmann <20h@r-36.net>
Date: Tue, 25 Dec 2012 10:20:35 +0100
Fixing the default symlink handling.
Diffstat:
cfg.c | | | 19 | +++++++++++++------ |
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/cfg.c b/cfg.c
@@ -11,6 +11,8 @@
#include <strings.h>
#include <errno.h>
#include <libgen.h>
+#include <sys/stat.h>
+#include <sys/types.h>
#include "ind.h"
#include "arg.h"
@@ -45,16 +47,19 @@ void
config_default(char *cfgn)
{
char *path, *cwd;
+ struct stat sbuf;
cwd = getcwd(NULL, 0);
if (cwd == NULL)
edie("getcwd");
- path = path_mkbasepath(cfgn);
+ path = path_mkrppath(NULL);
if (chdir(path) < 0)
edie("chdir");
- if (remove("default") < 0)
- edie("remove");
+ if (stat("default", &sbuf) >= 0) {
+ if (remove("default") < 0)
+ edie("remove");
+ }
if (symlink(cfgn, "default") < 0)
edie("symlink");
@@ -208,9 +213,11 @@ configmain(int argc, char *argv[])
cfg = config_init(cfgn);
if (status & DOLIST) {
- llist_sort(cfg->values);
- forllist(cfg->values, elem)
- configprintelem(elem, status & ONLYDATA);
+ if (config_len(cfg) > 0) {
+ llist_sort(cfg->values);
+ forllist(cfg->values, elem)
+ configprintelem(elem, status & ONLYDATA);
+ }
return 0;
}