mkdir_parents_label(to, 0755);
if (symlink(from, to) < 0)
- return log_error_errno(errno, "Failed to create symlink \"%s\": %m", to);
+ if (errno != EEXIST)
+ return log_error_errno(errno, "Failed to create symlink \"%s\": %m", to);
return 0;
}
#include "exit-status.h"
#include "fd-util.h"
#include "fileio.h"
+#include "generator.h"
#include "hashmap.h"
#include "hexdecoct.h"
#include "install.h"
hashmap_free(*h);
}
-static int add_symlink(const char *service, const char *where) {
- const char *from, *to;
- int r;
-
- assert(service);
- assert(where);
-
- from = strjoina(arg_dest, "/", service);
- to = strjoina(arg_dest, "/", where, ".wants/", service);
-
- mkdir_parents_label(to, 0755);
-
- r = symlink(from, to);
- if (r < 0) {
- if (errno == EEXIST)
- return 0;
-
- return -errno;
- }
-
- return 1;
-}
-
static int add_alias(const char *service, const char *alias) {
const char *link;
int r;
if (r < 0)
return log_error_errno(r, "Failed to write unit %s: %m", unit);
- STRV_FOREACH(p, s->wanted_by) {
- r = add_symlink(s->name, *p);
- if (r < 0)
- log_warning_errno(r, "Failed to create 'Wants' symlink to %s, ignoring: %m", *p);
- }
+ STRV_FOREACH(p, s->wanted_by)
+ (void) generator_add_symlink(arg_dest, *p, "wants", s->name);
return 1;
}
link = os.path.join(self.out_dir, '%s.target.wants' % target, unit)
if target in targets:
unit_file = os.readlink(link)
- self.assertTrue(os.path.exists(unit_file))
+ # os.path.exists() will fail on a dangling symlink
+ self.assertTrue(os.path.exists(link))
self.assertEqual(os.path.basename(unit_file), unit)
else:
self.assertFalse(os.path.exists(link),