TLS_OBJ = tls.o syscall.o lib/permstring.o
# Programs we must have to run the test cases
-CHECK_PROGS = rsync tls getgroups
+CHECK_PROGS = rsync tls getgroups trimslash
# note that the -I. is needed to handle config.h when using VPATH
.c.o:
getgroups: getgroups.o
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS)
+TRIMSLASH_OBJ = trimslash.o syscall.o
+trimslash: $(TRIMSLASH_OBJ)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(TRIMSLASH_OBJ) $(LIBS)
+
Makefile: Makefile.in configure config.status
echo "WARNING: You need to run ./config.status --recheck"
cat $(srcdir)/*.c $(srcdir)/lib/compat.c | awk -f $(srcdir)/mkproto.awk > $(srcdir)/proto.h
clean: cleantests
- rm -f *~ $(OBJS) rsync $(TLS_OBJ) tls getgroups
+ rm -f *~ $(OBJS) rsync $(TLS_OBJ) $(CHECK_PROGS)
cleantests:
rm -rf ./testtmp*
void trim_trailing_slashes(char *name)
{
- char *p;
+ int l;
/* Some BSD systems cannot make a directory if the name
* contains a trailing slash.
* <http://www.opensource.apple.com/bugs/X/BSD%20Kernel/2734739.html> */
- if (!*name)
- return; /* empty string */
- p = strchr(name, '\0') - 1;
- while (p == '/') {
- p-- = '\0';
+
+ /* Don't change empty string; and also we can't improve on
+ * "/" */
+
+ l = strlen(name);
+ while (l > 1) {
+ if (name[--l] != '/')
+ break;
+ name[l] = '\0';
}
}
--- /dev/null
+#! /bin/sh
+
+# Copyright (C) 2002 by Martin Pool <mbp@samba.org>
+
+# This program is distributable under the terms of the GNU GPL (see
+# COPYING).
+
+# Test tiny function to trim trailing slashes.
+
+. $srcdir/testsuite/rsync.fns
+
+set -x
+
+"$TOOLDIR/trimslash" "/usr/local/bin" "/usr/local/bin/" "/usr/local/bin///" \
+ "//a//" "////" \
+ "/Users/Wierd Macintosh Name/// Ooh, translucent plastic/" \
+ > "$scratchdir/slash.out"
+diff -c "$scratchdir/slash.out" - <<EOF
+/usr/local/bin
+/usr/local/bin
+/usr/local/bin
+//a
+/
+/Users/Wierd Macintosh Name/// Ooh, translucent plastic
+EOF
+
+exit 0
+# last [] may have failed but if we get here then we've won
+
--- /dev/null
+/*
+ * Copyright (C) 2002 by Martin Pool
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include "rsync.h"
+
+/* These are to make syscall.o shut up. */
+int dry_run = 0;
+int read_only = 1;
+int list_only = 0;
+
+/**
+ * @file trimslash.c
+ *
+ * Test harness; not linked into release.
+ **/
+int main(int argc, char **argv)
+{
+ int i;
+
+ if (argc <= 1) {
+ fprintf(stderr, "trimslash: needs at least one argument\n");
+ return 1;
+ }
+
+ for (i = 1; i < argc; i++) {
+ trim_trailing_slashes(argv[i]); /* modify in place */
+ printf("%s\n", argv[i]);
+ }
+ return 0;
+}