Be a bit more verbose
[rsync/rsync.git] / tls.c
... / ...
CommitLineData
1/* -*- c-file-style: "linux" -*-
2 *
3 * Copyright (C) 2001 by Martin Pool <mbp@samba.org>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License version
7 * 2 as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19/**
20 * \section tls
21 *
22 * tls -- Trivial recursive ls, for comparing two directories after
23 * running an rsync.
24 *
25 * The problem with using the system's own ls is that some features
26 * have little quirks that make directories look different when for
27 * our purposes they're the same -- for example, the BSD braindamage
28 * about setting the mode on symlinks based on your current umask.
29 *
30 * All the filenames must be given on the command line -- tls does not
31 * even read directories, let alone recurse. The typical usage is
32 * "find|sort|xargs tls".
33 *
34 * The format is not exactly the same as any particular Unix ls(1).
35 *
36 * A key requirement for this program is that the output be "very
37 * reproducible." So we mask away information that can accidentally
38 * change.
39 **/
40
41
42
43#include "rsync.h"
44
45#define PROGRAM "tls"
46
47/* These are to make syscall.o shut up. */
48int dry_run = 0;
49int read_only = 1;
50int list_only = 0;
51
52
53static void failed (char const *what,
54 char const *where)
55{
56 fprintf (stderr, PROGRAM ": %s %s: %s\n",
57 what, where, strerror (errno));
58 exit (1);
59}
60
61
62
63static void list_file (const char *fname)
64{
65 struct stat buf;
66 char permbuf[PERMSTRING_SIZE];
67 struct tm *mt;
68
69 if (do_lstat(fname, &buf) == -1)
70 failed ("stat", fname);
71
72 /* On some BSD platforms the mode bits of a symlink are
73 * undefined. */
74 if (S_ISLNK(buf.st_mode))
75 buf.st_mode &= ~0777;
76
77 /* The size of anything but a regular file is probably not
78 * worth thinking about. */
79 if (!S_ISREG(buf.st_mode))
80 buf.st_size = 0;
81
82 permstring(permbuf, buf.st_mode);
83
84 mt = gmtime(&buf.st_mtime);
85
86 /* TODO: Perhaps escape special characters in fname? */
87
88 /* NB: need to pass size as a double because it might be be
89 * too large for a long. */
90 printf("%s %12.0f %6d.%-6d %04d-%02d-%02d %02d:%02d:%02d %s\n",
91 permbuf, (double) buf.st_size,
92 buf.st_uid, buf.st_gid,
93 mt->tm_year + 1900,
94 mt->tm_mon + 1,
95 mt->tm_mday,
96 mt->tm_hour,
97 mt->tm_min,
98 mt->tm_sec,
99 fname);
100}
101
102
103int main (int argc, char *argv[])
104{
105 if (argc < 2) {
106 fprintf (stderr, "usage: " PROGRAM " DIR ...\n"
107 "Trivial file listing program for portably checking rsync\n");
108 return 1;
109 }
110
111 for (argv++; *argv; argv++) {
112 list_file (*argv);
113 }
114
115 return 0;
116}