Skip to content

Commit ce0f7f5

Browse files
committed
condition: reverse if check to lower indentation level
No change in behaviour. Let's just prefer early exit over deeper indentation.
1 parent f8b4ae2 commit ce0f7f5

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

src/shared/condition.c

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -602,29 +602,27 @@ static int condition_test_needs_update(Condition *c, char **env) {
602602
* AND the target file's nanoseconds == 0
603603
* (otherwise the filesystem supports nsec timestamps, see stat(2)).
604604
*/
605-
if (usr.st_mtim.tv_nsec > 0 && other.st_mtim.tv_nsec == 0) {
606-
_cleanup_free_ char *timestamp_str = NULL;
607-
uint64_t timestamp;
605+
if (usr.st_mtim.tv_nsec == 0 || other.st_mtim.tv_nsec > 0)
606+
return usr.st_mtim.tv_nsec > other.st_mtim.tv_nsec;
608607

609-
r = parse_env_file(NULL, p, "TIMESTAMP_NSEC", &timestamp_str);
610-
if (r < 0) {
611-
log_debug_errno(r, "Failed to parse timestamp file '%s', using mtime: %m", p);
612-
return true;
613-
} else if (r == 0) {
614-
log_debug("No data in timestamp file '%s', using mtime.", p);
615-
return true;
616-
}
617-
618-
r = safe_atou64(timestamp_str, &timestamp);
619-
if (r < 0) {
620-
log_debug_errno(r, "Failed to parse timestamp value '%s' in file '%s', using mtime: %m", timestamp_str, p);
621-
return true;
622-
}
608+
_cleanup_free_ char *timestamp_str = NULL;
609+
r = parse_env_file(NULL, p, "TIMESTAMP_NSEC", &timestamp_str);
610+
if (r < 0) {
611+
log_debug_errno(r, "Failed to parse timestamp file '%s', using mtime: %m", p);
612+
return true;
613+
} else if (r == 0) {
614+
log_debug("No data in timestamp file '%s', using mtime.", p);
615+
return true;
616+
}
623617

624-
return timespec_load_nsec(&usr.st_mtim) > timestamp;
618+
uint64_t timestamp;
619+
r = safe_atou64(timestamp_str, &timestamp);
620+
if (r < 0) {
621+
log_debug_errno(r, "Failed to parse timestamp value '%s' in file '%s', using mtime: %m", timestamp_str, p);
622+
return true;
625623
}
626624

627-
return usr.st_mtim.tv_nsec > other.st_mtim.tv_nsec;
625+
return timespec_load_nsec(&usr.st_mtim) > timestamp;
628626
}
629627

630628
static int condition_test_first_boot(Condition *c, char **env) {

0 commit comments

Comments
 (0)