Deleted Added
full compact
test_option_u.c (228763) test_option_u.c (232153)
1/*-
2 * Copyright (c) 2003-2007 Tim Kientzle
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 14 unchanged lines hidden (view full) ---

23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25#include "test.h"
26#if defined(HAVE_UTIME_H)
27#include <utime.h>
28#elif defined(HAVE_SYS_UTIME_H)
29#include <sys/utime.h>
30#endif
1/*-
2 * Copyright (c) 2003-2007 Tim Kientzle
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 14 unchanged lines hidden (view full) ---

23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25#include "test.h"
26#if defined(HAVE_UTIME_H)
27#include <utime.h>
28#elif defined(HAVE_SYS_UTIME_H)
29#include <sys/utime.h>
30#endif
31__FBSDID("$FreeBSD: head/contrib/libarchive/cpio/test/test_option_u.c 228763 2011-12-21 11:13:29Z mm $");
31__FBSDID("$FreeBSD: head/contrib/libarchive/cpio/test/test_option_u.c 232153 2012-02-25 10:58:02Z mm $");
32
33DEFINE_TEST(test_option_u)
34{
35 struct utimbuf times;
36 char *p;
37 size_t s;
38 int r;
39
40 /* Create a file. */
41 assertMakeFile("f", 0644, "a");
42
43 /* Copy the file to the "copy" dir. */
32
33DEFINE_TEST(test_option_u)
34{
35 struct utimbuf times;
36 char *p;
37 size_t s;
38 int r;
39
40 /* Create a file. */
41 assertMakeFile("f", 0644, "a");
42
43 /* Copy the file to the "copy" dir. */
44 r = systemf("echo f | %s -pd copy >copy.out 2>copy.err",
44 r = systemf("echo f| %s -pd copy >copy.out 2>copy.err",
45 testprog);
46 assertEqualInt(r, 0);
47
48 /* Check that the file contains only a single "a" */
49 p = slurpfile(&s, "copy/f");
50 assertEqualInt(s, 1);
51 assertEqualMem(p, "a", 1);
52
53 /* Recreate the file with a single "b" */
54 assertMakeFile("f", 0644, "b");
55
56 /* Set the mtime to the distant past. */
57 memset(&times, 0, sizeof(times));
58 times.actime = 1;
59 times.modtime = 3;
60 assertEqualInt(0, utime("f", &times));
61
62 /* Copy the file to the "copy" dir. */
45 testprog);
46 assertEqualInt(r, 0);
47
48 /* Check that the file contains only a single "a" */
49 p = slurpfile(&s, "copy/f");
50 assertEqualInt(s, 1);
51 assertEqualMem(p, "a", 1);
52
53 /* Recreate the file with a single "b" */
54 assertMakeFile("f", 0644, "b");
55
56 /* Set the mtime to the distant past. */
57 memset(&times, 0, sizeof(times));
58 times.actime = 1;
59 times.modtime = 3;
60 assertEqualInt(0, utime("f", &times));
61
62 /* Copy the file to the "copy" dir. */
63 r = systemf("echo f | %s -pd copy >copy.out 2>copy.err",
63 r = systemf("echo f| %s -pd copy >copy.out 2>copy.err",
64 testprog);
65 assertEqualInt(r, 0);
66
67 /* Verify that the file hasn't changed (it wasn't overwritten) */
68 p = slurpfile(&s, "copy/f");
69 assertEqualInt(s, 1);
70 assertEqualMem(p, "a", 1);
71
72 /* Copy the file to the "copy" dir with -u (force) */
64 testprog);
65 assertEqualInt(r, 0);
66
67 /* Verify that the file hasn't changed (it wasn't overwritten) */
68 p = slurpfile(&s, "copy/f");
69 assertEqualInt(s, 1);
70 assertEqualMem(p, "a", 1);
71
72 /* Copy the file to the "copy" dir with -u (force) */
73 r = systemf("echo f | %s -pud copy >copy.out 2>copy.err",
73 r = systemf("echo f| %s -pud copy >copy.out 2>copy.err",
74 testprog);
75 assertEqualInt(r, 0);
76
77 /* Verify that the file has changed (it was overwritten) */
78 p = slurpfile(&s, "copy/f");
79 assertEqualInt(s, 1);
80 assertEqualMem(p, "b", 1);
81}
74 testprog);
75 assertEqualInt(r, 0);
76
77 /* Verify that the file has changed (it was overwritten) */
78 p = slurpfile(&s, "copy/f");
79 assertEqualInt(s, 1);
80 assertEqualMem(p, "b", 1);
81}