summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Brown <ben.brown@codethink.co.uk>2013-10-29 10:26:49 +0000
committerBen Brown <ben.brown@codethink.co.uk>2013-11-01 14:19:05 +0000
commitf6fdf1dba0222ef5be16c5288b35f7aa47c43085 (patch)
treed2d9c9967ff6b34cc9c5bc1c634c824996b64bf8
parent496357d52383d438bf8ed363f8d614736fa63401 (diff)
downloadtbdiff-f6fdf1dba0222ef5be16c5288b35f7aa47c43085.tar.gz
Added symlink scenarios and a C program that changes the mtimes of symlinks.
-rw-r--r--yarns/create-deploy.yarn215
-rw-r--r--yarns/symtime.c41
2 files changed, 183 insertions, 73 deletions
diff --git a/yarns/create-deploy.yarn b/yarns/create-deploy.yarn
index 6cb9a4a..abf8681 100644
--- a/yarns/create-deploy.yarn
+++ b/yarns/create-deploy.yarn
@@ -12,13 +12,13 @@ This simple test checks that file content is as expected, if the content of
the two text files are different, the test will fail.
SCENARIO Changing a regular file's content works
- GIVEN a directory exists named 'A'
- AND the directory 'A' contains a regular file named 'foo.txt' with '1' in it
- AND a directory exists named 'B'
- AND the directory 'B' contains a regular file named 'foo.txt' with '2' in it
- WHEN tbdiff-create creates a binary delta named 'AB.tbdiff' from 'A' to 'B'
- AND tbdiff-deploy applies the delta 'AB.tbdiff' to 'A'
- THEN the files 'A/foo.txt' and 'B/foo.txt' have the same contents
+ GIVEN a directory exists named 'A_dir'
+ AND the directory 'A_dir' contains a regular file named 'foo_file' with '1' in it
+ AND a directory exists named 'B_dir'
+ AND the directory 'B_dir' contains a regular file named 'foo_file' with '2' in it
+ WHEN tbdiff-create creates a binary delta named 'AB.tbdiff' from 'A_dir' to 'B_dir'
+ AND tbdiff-deploy applies the delta 'AB.tbdiff' to 'A_dir'
+ THEN the files 'A_dir/foo_file' and 'B_dir/foo_file' have the same contents
Changing of a file's ownership
------------------------------
@@ -27,24 +27,36 @@ Trebuchet also takes into account POSIX metadata such as ownership, these
scenarios are written to test that functionality.
SCENARIO Changing a regular file's group ownership works
- GIVEN a directory exists named 'C'
- AND the directory 'C' contains a regular file named 'bar'
- AND a directory exists named 'D'
- AND the directory 'D' contains a regular file named 'bar'
- AND the file 'D/bar' is owned by the group '893'
- WHEN tbdiff-create creates a binary delta named 'CD.tbdiff' from 'C' to 'D'
- AND tbdiff-deploy applies the delta 'CD.tbdiff' to 'C'
- THEN the file 'C/bar' is owned by the group '893'
+ GIVEN a directory exists named 'C_dir'
+ AND the directory 'C_dir' contains a regular file named 'foo_file'
+ AND a directory exists named 'D_dir'
+ AND the directory 'D_dir' contains a regular file named 'foo_file'
+ AND the file 'D_dir/foo_file' is owned by the group '893'
+ WHEN tbdiff-create creates a binary delta named 'CD.tbdiff' from 'C_dir' to 'D_dir'
+ AND tbdiff-deploy applies the delta 'CD.tbdiff' to 'C_dir'
+ THEN the file 'C_dir/foo_file' is owned by the group '893'
SCENARIO Changing a named pipe's group ownership works
- GIVEN a directory exists named 'E'
- AND the directory 'E' contains the named pipe 'red'
- AND a directory exists named 'F'
- AND the directory 'F' contains the named pipe 'red'
- AND the file 'F/red' is owned by the group '594'
- WHEN tbdiff-create creates a binary delta named 'EF.tbdiff' from 'E' to 'F'
- AND tbdiff-deploy applies the delta 'EF.tbdiff' to 'E'
- THEN the file 'E/red' is owned by the group '594'
+ GIVEN a directory exists named 'E_dir'
+ AND the directory 'E_dir' contains the named pipe 'bar_pipe'
+ AND a directory exists named 'F_dir'
+ AND the directory 'F_dir' contains the named pipe 'bar_pipe'
+ AND the file 'F_dir/bar_pipe' is owned by the group '594'
+ WHEN tbdiff-create creates a binary delta named 'EF.tbdiff' from 'E_dir' to 'F_dir'
+ AND tbdiff-deploy applies the delta 'EF.tbdiff' to 'E_dir'
+ THEN the file 'E_dir/bar_pipe' is owned by the group '594'
+
+ SCENARIO Changing a symbolic link's group ownership works
+ GIVEN a directory exists named 'G_dir'
+ AND the directory 'G_dir' contains a regular file named 'foo_file'
+ AND the directory 'G_dir' contains the symbolic link 'link_to_foo_file' referring to 'G_dir/foo_file'
+ AND a directory exists named 'H_dir'
+ AND the directory 'H_dir' contains a regular file named 'foo_file'
+ AND the directory 'H_dir' contains the symbolic link 'link_to_foo_file' referring to 'H_dir/foo_file'
+ AND the symbolic link 'H_dir/link_to_foo_file' is owned by the group '608'
+ WHEN tbdiff-create creates a binary delta named 'GH.tbdiff' from 'G_dir' to 'H_dir'
+ AND tbdiff-deploy applies the delta 'GH.tbdiff' to 'G_dir'
+ THEN the file 'G_dir/link_to_foo_file' is owned by the group '608'
Changing of a file's permissions
--------------------------------
@@ -53,24 +65,24 @@ These scenarios test that file permissions are successfully changed after
the deployment of a binary delta.
SCENARIO Changing a file's permissions works
- GIVEN a directory exists named 'G'
- AND the directory 'G' contains a regular file named 'baz'
- AND a directory exists named 'H'
- AND the directory 'H' contains a regular file named 'baz'
- AND the file 'H/baz' has the permissions 'ugo=rw'
- WHEN tbdiff-create creates a binary delta named 'GH.tbdiff' from 'G' to 'H'
- AND tbdiff-deploy applies the delta 'GH.tbdiff' to 'G'
- THEN the file 'G/baz' has the permissions '-rw-rw-rw-'
+ GIVEN a directory exists named 'I_dir'
+ AND the directory 'I_dir' contains a regular file named 'foo_file'
+ AND a directory exists named 'J_dir'
+ AND the directory 'J_dir' contains a regular file named 'foo_file'
+ AND the file 'J_dir/foo_file' has the permissions 'ugo=rw'
+ WHEN tbdiff-create creates a binary delta named 'IJ.tbdiff' from 'I_dir' to 'J_dir'
+ AND tbdiff-deploy applies the delta 'IJ.tbdiff' to 'I_dir'
+ THEN the file 'I_dir/foo_file' has the permissions '-rw-rw-rw-'
SCENARIO Changing a named pipe's permissions works
- GIVEN a directory exists named 'I'
- AND the directory 'I' contains the named pipe 'orange'
- AND a directory exists named 'J'
- AND the directory 'J' contains the named pipe 'orange'
- AND the file 'J/orange' has the permissions 'ug=rw,o=r'
- WHEN tbdiff-create creates a binary delta named 'IJ.tbdiff' from 'I' to 'J'
- AND tbdiff-deploy applies the delta 'IJ.tbdiff' to 'I'
- THEN the file 'I/orange' has the permissions 'prw-rw-r--'
+ GIVEN a directory exists named 'K_dir'
+ AND the directory 'K_dir' contains the named pipe 'bar_pipe'
+ AND a directory exists named 'L_dir'
+ AND the directory 'L_dir' contains the named pipe 'bar_pipe'
+ AND the file 'L_dir/bar_pipe' has the permissions 'ug=rw,o=r'
+ WHEN tbdiff-create creates a binary delta named 'KL.tbdiff' from 'K_dir' to 'L_dir'
+ AND tbdiff-deploy applies the delta 'KL.tbdiff' to 'K_dir'
+ THEN the file 'K_dir/bar_pipe' has the permissions 'prw-rw-r--'
Adding and removing of files
----------------------------
@@ -79,24 +91,36 @@ The following scenarios check that the deploying of a binary delta
successfully removes and creates the appropriate files.
SCENARIO Adding and removing of regular files works
- GIVEN a directory exists named 'K'
- AND the directory 'K' contains a regular file named 'minus'
- AND a directory exists named 'L'
- AND the directory 'L' contains a regular file named 'plus'
- WHEN tbdiff-create creates a binary delta named 'KL.tbdiff' from 'K' to 'L'
- AND tbdiff-deploy applies the delta 'KL.tbdiff' to 'K'
- THEN the file 'K/minus' no longer exists
- AND the directory 'K' contains a file named 'plus'
+ GIVEN a directory exists named 'M_dir'
+ AND the directory 'M_dir' contains a regular file named 'minus_file'
+ AND a directory exists named 'N_dir'
+ AND the directory 'N_dir' contains a regular file named 'plus_file'
+ WHEN tbdiff-create creates a binary delta named 'MN.tbdiff' from 'M_dir' to 'N_dir'
+ AND tbdiff-deploy applies the delta 'MN.tbdiff' to 'M_dir'
+ THEN the file 'M_dir/minus_file' no longer exists
+ AND the directory 'M_dir' contains a file named 'plus_file'
SCENARIO Adding and removing of named pipes works
- GIVEN a directory exists named 'M'
- AND the directory 'M' contains the named pipe 'yellow'
- AND a directory exists named 'N'
- AND the directory 'N' contains the named pipe 'green'
- WHEN tbdiff-create creates a binary delta named 'MN.tbdiff' from 'M' to 'N'
- AND tbdiff-deploy applies the delta 'MN.tbdiff' to 'M'
- THEN the file 'M/yellow' no longer exists
- AND the directory 'M' contains the named pipe 'green'
+ GIVEN a directory exists named 'O_dir'
+ AND the directory 'O_dir' contains the named pipe 'minus_pipe'
+ AND a directory exists named 'P_dir'
+ AND the directory 'P_dir' contains the named pipe 'plus_pipe'
+ WHEN tbdiff-create creates a binary delta named 'OP.tbdiff' from 'O_dir' to 'P_dir'
+ AND tbdiff-deploy applies the delta 'OP.tbdiff' to 'O_dir'
+ THEN the file 'O_dir/minus_pipe' no longer exists
+ AND the directory 'O_dir' contains the named pipe 'plus_pipe'
+
+ SCENARIO Adding and removing of symbolic links works
+ GIVEN a directory exists named 'Q_dir'
+ AND the directory 'Q_dir' contains a regular file named 'minus_file'
+ AND the directory 'Q_dir' contains the symbolic link 'link_to_minus_file' referring to 'Q_dir/minus_file'
+ AND a directory exists named 'R_dir'
+ AND the directory 'R_dir' contains a regular file named 'plus_file'
+ AND the directory 'R_dir' contains the symbolic link 'link_to_plus_file' referring to 'R_dir/plus_file'
+ WHEN tbdiff-create creates a binary delta named 'QR.tbdiff' from 'Q_dir' to 'R_dir'
+ AND tbdiff-deploy applies the delta 'QR.tbdiff' to 'Q_dir'
+ THEN the file 'Q_dir/link_to_minus_file' no longer exists
+ AND the directory 'Q_dir' contains the symbolic link 'link_to_plus_file'
Changing modification time of a file
------------------------------------
@@ -105,26 +129,56 @@ In the following scenarios we check that modification times are correctly
changed, if modification times are not identical, the test fails.
SCENARIO Changing a file's modification time works
- GIVEN a directory exists named 'O'
- AND the directory 'O' contains a regular file named 'hurr' with '1' in it
- AND the file 'O/hurr' has its modification time set to '@793042334'
- AND a directory exists named 'P'
- AND the directory 'P' contains a regular file named 'hurr' with '1' in it
- AND the file 'P/hurr' has its modification time set to '@683074800'
- WHEN tbdiff-create creates a binary delta named 'OP.tbdiff' from 'O' to 'P'
- AND tbdiff-deploy applies the delta 'OP.tbdiff' to 'O'
- THEN the files 'O/hurr' and 'P/hurr' have the same modification time
+ GIVEN a directory exists named 'S_dir'
+ AND the directory 'S_dir' contains a regular file named 'foo_file' with '1' in it
+ AND the file 'S_dir/foo_file' has its modification time set to '@1381758015'
+ AND a directory exists named 'T_dir'
+ AND the directory 'T_dir' contains a regular file named 'foo_file' with '1' in it
+ AND the file 'T_dir/foo_file' has its modification time set to '@683074800'
+ WHEN tbdiff-create creates a binary delta named 'ST.tbdiff' from 'S_dir' to 'T_dir'
+ AND tbdiff-deploy applies the delta 'ST.tbdiff' to 'S_dir'
+ THEN the files 'S_dir/foo_file' and 'T_dir/foo_file' have the same modification time
SCENARIO Changing a named pipe's modification time works
- GIVEN a directory exists named 'Q'
- AND the directory 'Q' contains the named pipe 'blue'
- AND the file 'Q/blue' has its modification time set to '@1381758015'
- AND a directory exists named 'R'
- AND the directory 'R' contains the named pipe 'blue'
- AND the file 'R/blue' has its modification time set to '@683074800'
- WHEN tbdiff-create creates a binary delta named 'QR.tbdiff' from 'Q' to 'R'
- AND tbdiff-deploy applies the delta 'QR.tbdiff' to 'Q'
- THEN the files 'Q/blue' and 'R/blue' have the same modification time
+ GIVEN a directory exists named 'U_dir'
+ AND the directory 'U_dir' contains the named pipe 'bar_pipe'
+ AND the file 'U_dir/bar_pipe' has its modification time set to '@1381758015'
+ AND a directory exists named 'V_dir'
+ AND the directory 'V_dir' contains the named pipe 'bar_pipe'
+ AND the file 'V_dir/bar_pipe' has its modification time set to '@683074800'
+ WHEN tbdiff-create creates a binary delta named 'UV.tbdiff' from 'U_dir' to 'V_dir'
+ AND tbdiff-deploy applies the delta 'UV.tbdiff' to 'U_dir'
+ THEN the files 'U_dir/bar_pipe' and 'V_dir/bar_pipe' have the same modification time
+
+ SCENARIO Changing a symbolic links modification time works
+ GIVEN a directory exists named 'W_dir'
+ AND the directory 'W_dir' contains a regular file named 'foo_file'
+ AND the directory 'W_dir' contains the symbolic link 'link_to_foo_file' referring to 'W_dir/foo_file'
+ AND the symbolic link 'W_dir/link_to_foo_file' has its modification time set to '1381758015'
+ AND a directory exists named 'X_dir'
+ AND the directory 'X_dir' contains a regular file named 'foo_file'
+ AND the directory 'X_dir' contains the symbolic link 'link_to_foo_file' referring to 'X_dir/foo_file'
+ AND the symbolic link 'X_dir/link_to_foo_file' has its modification time set to '683074800'
+ WHEN tbdiff-create creates a binary delta named 'WX.tbdiff' from 'W_dir' to 'X_dir'
+ AND tbdiff-deploy applies the delta 'WX.tbdiff' to 'W_dir'
+ THEN the files 'W_dir/link_to_foo_file' and 'X_dir/link_to_foo_file' have the same modification time
+
+Changing what a symbolic link refers to
+---------------------------------------
+
+This scenario checks that referenced files of symbolic links are correctly
+transformed.
+
+ SCENARIO Changing what a symbolic link refers to works
+ GIVEN a directory exists named 'Y_dir'
+ AND the directory 'Y_dir' contains a regular file named 'foo_file'
+ AND the directory 'Y_dir' contains the symbolic link 'link_to_foo_file' referring to 'Y_dir/foo_file'
+ AND a directory exists named 'Z_dir'
+ AND the directory 'Z_dir' contains a regular file named 'foo_file'
+ AND the directory 'Z_dir' contains the symbolic link 'link_to_foo_file' referring to 'Z_dir/foo_file'
+ WHEN tbdiff-create creates a binary delta named 'YZ.tbdiff' from 'Y_dir' to 'Z_dir'
+ AND tbdiff-deploy applies the delta 'YZ.tbdiff' to 'Y_dir'
+ THEN the symbolic links 'Y_dir/link_to_foo_file' and 'Z_dir/link_to_foo_file' refer to the same thing
IMPLEMENTS
==========
@@ -144,15 +198,24 @@ Implementations for the creating and deploying of binary deltas
IMPLEMENTS GIVEN the file '([^']+)' is owned by the group '([^']+)'
chgrp "$MATCH_2" "$DATADIR/$MATCH_1"
+ IMPLEMENTS GIVEN the symbolic link '([^']+)' is owned by the group '([^']+)'
+ chgrp -h "$MATCH_2" "$DATADIR/$MATCH_1"
+
IMPLEMENTS GIVEN the file '([^']+)' has the permissions '([^']+)'
chmod "$MATCH_2" "$DATADIR/$MATCH_1"
IMPLEMENTS GIVEN the file '([^']+)' has its modification time set to '([^']+)'
touch -d "$MATCH_2" "$DATADIR/$MATCH_1"
+ IMPLEMENTS GIVEN the symbolic link '([^']+)' has its modification time set to '([^']+)'
+ "$SRCDIR/symtime" "$DATADIR/$MATCH_1" "$MATCH_2"
+
IMPLEMENTS GIVEN the directory '([^']+)' contains the named pipe '([^']+)'
mkfifo "$DATADIR/$MATCH_1/$MATCH_2"
+ IMPLEMENTS GIVEN the directory '([^']+)' contains the symbolic link '([^']+)' referring to '([^']+)'
+ ln -s "$DATADIR/$MATCH_3" "$DATADIR/$MATCH_1/$MATCH_2"
+
IMPLEMENTS WHEN tbdiff-create creates a binary delta named '([^']+)' from '([^']+)' to '([^']+)'
"$SRCDIR/tbdiff-create/tbdiff-create" "$DATADIR/$MATCH_1" "$DATADIR/$MATCH_2" "$DATADIR/$MATCH_3"
@@ -180,3 +243,9 @@ Implementations for the creating and deploying of binary deltas
IMPLEMENTS THEN the directory '([^']+)' contains the named pipe '([^']+)'
test -p "$DATADIR/$MATCH_1/$MATCH_2"
+
+ IMPLEMENTS THEN the directory '([^']+)' contains the symbolic link '([^']+)'
+ test -h "$DATADIR/$MATCH_1/$MATCH_2"
+
+ IMPLEMENTS THEN the symbolic links '([^']+)' and '([^']+)' refer to the same thing
+ test "$(readlink "$DATADIR/$MATCH_1")" = "$(readlink "$DATADIR/$MATCH_2")"
diff --git a/yarns/symtime.c b/yarns/symtime.c
new file mode 100644
index 0000000..73471ef
--- /dev/null
+++ b/yarns/symtime.c
@@ -0,0 +1,41 @@
+#define _BSD_SOURCE
+#include <stdlib.h>
+#include <sys/time.h>
+#include <stdio.h>
+#include <err.h>
+
+/*
+ * Busybox touch currently doesn't do any special symlink handling; this
+ * program is used to change the modification times of symbolic links.
+ */
+
+int set_link_mtime(char *filepath, int mtime)
+{
+ struct timeval tv[2] = { {.tv_sec = mtime}, {.tv_sec = mtime} };
+
+ if (lutimes(filepath, tv) == -1) {
+ err(EXIT_FAILURE, NULL);
+ }
+
+ return EXIT_SUCCESS;
+}
+
+int main(int argc, char *argv[])
+{
+ char *endptr;
+ long mtime;
+
+ if (argc != 3) {
+ fprintf(stderr, "Usage: %s FILE_PATH TIMESTAMP\n", argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ mtime = strtol(argv[2], &endptr, 10);
+
+ if (*endptr != '\0') {
+ fprintf(stderr, "TIMESTAMP must not include non-digits\n");
+ return EXIT_FAILURE;
+ }
+
+ return set_link_mtime(argv[1], mtime);
+}