Commit | Line | Data |
---|---|---|
f22ee865 MP |
1 | /* -*- c-file-style: "linux" -*- |
2 | * | |
3 | * Copyright (C) 2001 by Martin Pool | |
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 | * There are some restrictions compared to regular ls: all the names | |
31 | * on the command line must be directories rather than files; you | |
32 | * can't give wildcards either. | |
33 | * | |
f22ee865 MP |
34 | * We need to recurse downwards and show all the interesting |
35 | * information and no more. | |
36 | * | |
37 | * \todo Use readdir64 if available? | |
f7ca98bd MP |
38 | * |
39 | * \todo Sort directory entries. Either that, or output file listing | |
40 | * in such a format that we can just pipe the whole lot through sort. | |
f22ee865 MP |
41 | */ |
42 | ||
43 | ||
44 | ||
45 | #include "rsync.h" | |
46 | ||
47 | #define PROGRAM "tls" | |
48 | ||
49 | /* These are to make syscall.o shut up. */ | |
50 | int dry_run = 0; | |
51 | int read_only = 1; | |
52 | int list_only = 0; | |
53 | ||
54 | ||
55 | static void failed (char const *what, | |
56 | char const *where) | |
57 | { | |
58 | fprintf (stderr, PROGRAM ": %s %s: %s\n", | |
59 | what, where, strerror (errno)); | |
60 | exit (1); | |
61 | } | |
62 | ||
63 | ||
64 | ||
65 | static void list_dir (char const *dn) | |
66 | { | |
67 | DIR *d; | |
68 | struct dirent *de; | |
69 | ||
70 | if (!(d = opendir (dn))) | |
71 | failed ("opendir", dn); | |
72 | ||
73 | while ((de = readdir (d))) { | |
74 | char *dname = d_name (de); | |
75 | if (!strcmp (dname, ".") || !strcmp (dname, "..")) | |
76 | continue; | |
77 | printf ("%s\n", dname); | |
78 | } | |
79 | ||
80 | if (closedir (d) == -1) | |
81 | failed ("closedir", dn); | |
82 | } | |
83 | ||
84 | ||
85 | int main (int argc, char *argv[]) | |
86 | { | |
87 | if (argc < 2) { | |
88 | fprintf (stderr, "usage: " PROGRAM " DIR ...\n" | |
89 | "Trivial file listing program for portably checking rsync\n"); | |
90 | return 1; | |
91 | } | |
92 | ||
93 | for (argv++; *argv; argv++) { | |
94 | list_dir (*argv); | |
95 | } | |
96 | ||
97 | return 0; | |
98 | } |