00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include "rsync.h"
00042
00043 #define PROGRAM "tls"
00044
00045
00046 int dry_run = 0;
00047 int read_only = 1;
00048 int list_only = 0;
00049 int preserve_perms = 0;
00050
00051
00052 static void failed(char const *what, char const *where)
00053 {
00054 fprintf(stderr, PROGRAM ": %s %s: %s\n",
00055 what, where, strerror(errno));
00056 exit(1);
00057 }
00058
00059
00060
00061 static void list_file(const char *fname)
00062 {
00063 STRUCT_STAT buf;
00064 char permbuf[PERMSTRING_SIZE];
00065 struct tm *mt;
00066 char datebuf[50];
00067 char linkbuf[4096];
00068
00069 if (do_lstat(fname, &buf) < 0)
00070 failed("stat", fname);
00071
00072
00073
00074 if (!S_ISREG(buf.st_mode))
00075 buf.st_size = 0;
00076
00077
00078
00079
00080 if (S_ISLNK(buf.st_mode)) {
00081 int len;
00082 buf.st_mode &= ~0777;
00083 buf.st_mtime = (time_t)0;
00084 buf.st_uid = buf.st_gid = 0;
00085 strcpy(linkbuf, " -> ");
00086
00087 len = readlink((char *) fname, linkbuf+4, sizeof(linkbuf) - 4);
00088 if (len == -1)
00089 failed("readlink", fname);
00090 else
00091
00092 linkbuf[4+len] = 0;
00093 } else {
00094 linkbuf[0] = 0;
00095 }
00096
00097 permstring(permbuf, buf.st_mode);
00098
00099 if (buf.st_mtime) {
00100 mt = gmtime(&buf.st_mtime);
00101
00102 sprintf(datebuf, "%04d-%02d-%02d %02d:%02d:%02d",
00103 (int)mt->tm_year + 1900,
00104 (int)mt->tm_mon + 1,
00105 (int)mt->tm_mday,
00106 (int)mt->tm_hour,
00107 (int)mt->tm_min,
00108 (int)mt->tm_sec);
00109 } else {
00110 strcpy(datebuf, " ");
00111 }
00112
00113
00114
00115 printf("%s ", permbuf);
00116 if (S_ISCHR(buf.st_mode) || S_ISBLK(buf.st_mode)) {
00117 printf("%5ld,%6ld",
00118 (long)major(buf.st_rdev),
00119 (long)minor(buf.st_rdev));
00120 } else
00121 printf("%12.0f", (double)buf.st_size);
00122 printf(" %6ld.%-6ld %6ld %s %s%s\n",
00123 (long)buf.st_uid, (long)buf.st_gid, (long)buf.st_nlink,
00124 datebuf, fname, linkbuf);
00125 }
00126
00127
00128 int
00129 main(int argc, char *argv[])
00130 {
00131 if (argc < 2) {
00132 fprintf(stderr, "usage: " PROGRAM " DIR ...\n"
00133 "Trivial file listing program for portably checking rsync\n");
00134 return 1;
00135 }
00136
00137 for (argv++; *argv; argv++) {
00138 list_file(*argv);
00139 }
00140
00141 return 0;
00142 }