[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] Suggestion: new module link
From: |
Bruno Haible |
Subject: |
Re: [PATCH] Suggestion: new module link |
Date: |
Tue, 20 Jan 2009 01:21:43 +0100 |
User-agent: |
KMail/1.9.9 |
Hello Eric, Martin,
> > Or print a message and return 77, to skip the test, if the current fs
> > doesn't support links at this point (such as FAT).
>
> I'd like to do that, but it it not easy to detect this condition. POSIX
> does not specify an error code for it, Linux uses EPERM (which can also
> occur under different circumstances), FreeBSD uses EOPNOTSUPP
Thanks for these detail infos. I implemented Eric's suggestion as follows:
2009-01-19 Bruno Haible <address@hidden>
* tests/test-link.c: Include <errno.h>.
(main): Exit with code 77 when a hard link cannot be created due to
the file system.
* tests/test-link.sh: Skip test when a hard link cannot be created due
to the file system.
Suggested by Eric Blake.
--- tests/test-link.c.orig 2009-01-20 01:17:22.000000000 +0100
+++ tests/test-link.c 2009-01-20 01:13:52.000000000 +0100
@@ -18,6 +18,7 @@
#include <unistd.h>
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@@ -36,8 +37,20 @@
int
main (int argc, char **argv)
{
+ int ret;
+
ASSERT (argc == 3);
- ASSERT (link (argv[1], argv[2]) == 0);
+
+ ret = link (argv[1], argv[2]);
+ if (ret < 0)
+ {
+ /* If the device does not support hard links, errno is
+ EPERM on Linux, EOPNOTSUPP on FreeBSD. */
+ if (errno == EPERM || errno == EOPNOTSUPP)
+ return 77;
+ perror ("link");
+ return 1;
+ }
return 0;
}
--- tests/test-link.sh.orig 2009-01-20 01:17:22.000000000 +0100
+++ tests/test-link.sh 2009-01-20 01:17:09.000000000 +0100
@@ -7,7 +7,16 @@
echo "hello" > test-link-a.txt || exit 1
# Use link() to create a new name for it.
-./test-link${EXEEXT} test-link-a.txt test-link-b.txt || exit 1
+./test-link${EXEEXT} test-link-a.txt test-link-b.txt
+case $? in
+ 0) ;;
+ 77)
+ echo "Skipping test: hard links are not supported on this file system"
+ rm -fr $tmpfiles
+ exit 77
+ ;;
+ *) exit 1 ;;
+esac
cmp test-link-a.txt test-link-b.txt || exit 1
# Modify the contents of the first file.