aboutsummaryrefslogtreecommitdiff
path: root/src/librc/librc-depend.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2008-07-03 13:11:47 +0000
committerRoy Marples <roy@marples.name>2008-07-03 13:11:47 +0000
commita88a177f991527e545e75588013afd16c647e656 (patch)
treef759fbfc83664f9c5f502904c917c3c4ee8d6ca8 /src/librc/librc-depend.c
parentd61f8318962346b3b2a3f13e7b489d2c0c397b94 (diff)
Add older_than function to complement newer_than function. Also make the userland instance reversed to be compatable with current baselayout, which truely does suck.
Diffstat (limited to 'src/librc/librc-depend.c')
-rw-r--r--src/librc/librc-depend.c42
1 files changed, 31 insertions, 11 deletions
diff --git a/src/librc/librc-depend.c b/src/librc/librc-depend.c
index 5b7de424..145bdde6 100644
--- a/src/librc/librc-depend.c
+++ b/src/librc/librc-depend.c
@@ -553,12 +553,12 @@ rc_deptree_order(const RC_DEPTREE *deptree, const char *runlevel, int options)
}
librc_hidden_def(rc_deptree_order)
-bool
-rc_newer_than(const char *source, const char *target)
+static bool
+mtime_check(const char *source, const char *target, bool newer)
{
struct stat buf;
time_t mtime;
- bool newer = true;
+ bool retval = true;
DIR *dp;
struct dirent *d;
char path[PATH_MAX];
@@ -569,32 +569,52 @@ rc_newer_than(const char *source, const char *target)
return false;
mtime = buf.st_mtime;
- /* Of course we are newer than targets that don't exist
- such as broken symlinks */
+ /* If target does not exist, return true to mimic shell test */
if (stat(target, &buf) != 0)
return true;
- if (mtime < buf.st_mtime)
- return false;
+
+ if (newer) {
+ if (mtime < buf.st_mtime)
+ return false;
+ } else {
+ if (mtime > buf.st_mtime)
+ return false;
+ }
+
/* If not a dir then reset errno */
if (!(dp = opendir(target))) {
errno = serrno;
return true;
}
- /* Check if we're newer than all the entries in the dir */
+ /* Check all the entries in the dir */
while ((d = readdir(dp))) {
if (d->d_name[0] == '.')
continue;
snprintf(path, sizeof(path), "%s/%s", target, d->d_name);
- newer = rc_newer_than(source, path);
- if (! newer)
+ retval = mtime_check(source, path, newer);
+ if (!retval)
break;
}
closedir(dp);
- return newer;
+ return retval;
+}
+
+bool
+rc_newer_than(const char *source, const char *target)
+{
+
+ return mtime_check(source, target, true);
}
librc_hidden_def(rc_newer_than)
+bool
+rc_older_than(const char *source, const char *target)
+{
+ return mtime_check(source, target, false);
+}
+librc_hidden_def(rc_older_than)
+
typedef struct deppair
{
const char *depend;