shithub: scc

Download patch

ref: c980d9a167cf89793266ae7dfdf60fd20836dfec
parent: f197f3b93095925f0d4ad1bad90f0d0b2aef66cf
author: Quentin Rameau <quinq@fifth.space>
date: Wed Jan 9 19:11:13 EST 2019

[ar] Implement u flag

Update only older files in the archive.

--- a/src/cmd/ar.c
+++ b/src/cmd/ar.c
@@ -208,6 +208,16 @@
 	return 0;
 }
 
+static int
+older(struct member *m)
+{
+	struct fprop prop;
+
+	if (getstat(m->fname, &prop) < 0)
+		error("error getting '%s' attributes", m->fname);
+	return prop.time > m->date;
+}
+
 static void
 move(struct member *m, int argc, char *argv[])
 {
@@ -244,7 +254,8 @@
 	FILE *fp = tmps[BEFORE].fp;
 
 	if (inlist(m->fname, argc, argv)) {
-		archive(m->fname, tmps[m->cur].fp, 'r');
+		if (uflag && older(m))
+			archive(m->fname, tmps[m->cur].fp, 'r');
 		return;
 	} else if (posname && !strcmp(posname, m->fname)) {
 		where = (bflag) ? AFTER : BEFORE;
@@ -595,8 +606,6 @@
 		lflag = 1;
 		break;
 	case 'u':
-		/* TODO */
-		abort();
 		uflag = 1;
 		break;
 	default: