- char path[PATH_MAX];
-
- for (i = 0 ; i < count ; i++) {
- rc = get_unit_path(path, sizeof path, &descs[i]);
- if (rc >= 0) {
- rc = unlink(path);
+ char path[PATH_MAX + 1], target[PATH_MAX + 1];
+
+ i = 0;
+ while (i < count) {
+ rc = check_unit_desc(&descs[i], 1);
+ if (!rc) {
+ rc = get_unit_path(path, sizeof path, &descs[i]);
+ if (rc >= 0) {
+ rc = putfile(path, descs[i].content, descs[i].content_length);
+ if (descs[i].wanted_by != NULL) {
+ rc = get_wants_path(path, sizeof path, &descs[i]);
+ if (rc >= 0) {
+ rc = get_wants_target(target, sizeof target, &descs[i]);
+ if (rc >= 0) {
+ unlink(path); /* TODO? check? */
+ rc = symlink(target, path);
+ }
+ }
+ }
+ i++;
+ }
+ }
+ if (rc < 0) {
+ do_uninstall_units(closure, descs, i);
+ return rc;