| Martin Pool | 08a740f | 2001-08-15 06:41:24 +0000 | [diff] [blame] | 1 | /* -*- c-file-style: "linux" -*- |
| 2 | |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 3 | Weiss 1/1999 |
| Martin Pool | 08a740f | 2001-08-15 06:41:24 +0000 | [diff] [blame] | 4 | Batch utilities for rsync. |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 5 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 6 | */ |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 7 | |
| 8 | #include "rsync.h" |
| 9 | #include <time.h> |
| 10 | |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 11 | extern char *batch_prefix; |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 12 | |
| 13 | struct file_list *batch_flist; |
| 14 | |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 15 | static char rsync_flist_file[] = ".rsync_flist"; |
| 16 | static char rsync_csums_file[] = ".rsync_csums"; |
| 17 | static char rsync_delta_file[] = ".rsync_delta"; |
| 18 | static char rsync_argvs_file[] = ".rsync_argvs"; |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 19 | |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 20 | static int fdb; |
| 21 | static int fdb_delta; |
| 22 | static int fdb_open; |
| 23 | static int fdb_close; |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 24 | |
| 25 | void write_batch_flist_file(char *buff, int bytes_to_write) |
| 26 | { |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 27 | char filename[MAXPATHLEN]; |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 28 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 29 | if (fdb_open) { |
| 30 | /* Set up file extension */ |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 31 | strlcpy(filename, batch_prefix, sizeof(filename)); |
| 32 | strlcat(filename, rsync_flist_file, sizeof(filename)); |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 33 | |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 34 | /* |
| 35 | * Open batch flist file for writing; |
| 36 | * create it if it doesn't exist |
| 37 | */ |
| 38 | fdb = do_open(filename, O_WRONLY | O_CREAT | O_TRUNC, |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 39 | S_IREAD | S_IWRITE); |
| 40 | if (fdb == -1) { |
| 41 | rprintf(FERROR, "Batch file %s open error: %s\n", |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 42 | filename, strerror(errno)); |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 43 | close(fdb); |
| 44 | exit_cleanup(1); |
| 45 | } |
| 46 | fdb_open = 0; |
| 47 | } |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 48 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 49 | /* Write buffer to batch flist file */ |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 50 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 51 | if (write(fdb, buff, bytes_to_write) == -1) { |
| 52 | rprintf(FERROR, "Batch file %s write error: %s\n", |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 53 | filename, strerror(errno)); |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 54 | close(fdb); |
| 55 | exit_cleanup(1); |
| 56 | } |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 57 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 58 | if (fdb_close) { |
| 59 | close(fdb); |
| 60 | } |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | void write_batch_flist_info(int flist_count, struct file_struct **fptr) |
| 64 | { |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 65 | int i; |
| 66 | int bytes_to_write; |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 67 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 68 | /* Write flist info to batch file */ |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 69 | |
| Martin Pool | 76f79ba | 2002-01-23 05:51:06 +0000 | [diff] [blame] | 70 | bytes_to_write = |
| 71 | sizeof(unsigned) + |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 72 | sizeof(time_t) + |
| 73 | sizeof(OFF_T) + |
| 74 | sizeof(mode_t) + |
| Martin Pool | 6abd193 | 2002-01-11 08:25:32 +0000 | [diff] [blame] | 75 | sizeof(INO64_T) + |
| Martin Pool | 76f79ba | 2002-01-23 05:51:06 +0000 | [diff] [blame] | 76 | sizeof(DEV64_T) + |
| 77 | sizeof(DEV64_T) + |
| 78 | sizeof(uid_t) + |
| 79 | sizeof(gid_t); |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 80 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 81 | fdb_open = 1; |
| 82 | fdb_close = 0; |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 83 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 84 | for (i = 0; i < flist_count; i++) { |
| 85 | write_batch_flist_file((char *) fptr[i], bytes_to_write); |
| 86 | write_char_bufs(fptr[i]->basename); |
| 87 | write_char_bufs(fptr[i]->dirname); |
| 88 | write_char_bufs(fptr[i]->basedir); |
| 89 | write_char_bufs(fptr[i]->link); |
| 90 | if (i == flist_count - 1) { |
| 91 | fdb_close = 1; |
| 92 | } |
| 93 | write_char_bufs(fptr[i]->sum); |
| 94 | } |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | void write_char_bufs(char *buf) |
| 98 | { |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 99 | /* Write the size of the string which will follow */ |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 100 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 101 | char b[4]; |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 102 | |
| 103 | SIVAL(b, 0, buf != NULL ? strlen(buf) : 0); |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 104 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 105 | write_batch_flist_file(b, sizeof(int)); |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 106 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 107 | /* Write the string if there is one */ |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 108 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 109 | if (buf != NULL) { |
| 110 | write_batch_flist_file(buf, strlen(buf)); |
| 111 | } |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| Martin Pool | 76f79ba | 2002-01-23 05:51:06 +0000 | [diff] [blame] | 114 | void write_batch_argvs_file(int argc, char *argv[]) |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 115 | { |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 116 | int fdb; |
| 117 | int i; |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 118 | char buff[256]; /* XXX */ |
| 119 | char buff2[MAXPATHLEN + 6]; |
| 120 | char filename[MAXPATHLEN]; |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 121 | |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 122 | /* Set up file extension */ |
| 123 | strlcpy(filename, batch_prefix, sizeof(filename)); |
| 124 | strlcat(filename, rsync_argvs_file, sizeof(filename)); |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 125 | |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 126 | /* |
| 127 | * Open batch argvs file for writing; |
| 128 | * create it if it doesn't exist |
| 129 | */ |
| 130 | fdb = do_open(filename, O_WRONLY | O_CREAT | O_TRUNC, |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 131 | S_IREAD | S_IWRITE | S_IEXEC); |
| 132 | if (fdb == -1) { |
| 133 | rprintf(FERROR, "Batch file %s open error: %s\n", |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 134 | filename, strerror(errno)); |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 135 | close(fdb); |
| 136 | exit_cleanup(1); |
| 137 | } |
| 138 | buff[0] = '\0'; |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 139 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 140 | /* Write argvs info to batch file */ |
| 141 | |
| Martin Pool | 76f79ba | 2002-01-23 05:51:06 +0000 | [diff] [blame] | 142 | for (i = 0; i < argc; ++i) { |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 143 | if (i == argc - 2) /* Skip source directory on cmdline */ |
| Martin Pool | 76f79ba | 2002-01-23 05:51:06 +0000 | [diff] [blame] | 144 | continue; |
| 145 | /* |
| 146 | * FIXME: |
| 147 | * I think directly manipulating argv[] is probably bogus |
| 148 | */ |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 149 | if (!strncmp(argv[i], "--write-batch", |
| 150 | strlen("--write-batch"))) { |
| Martin Pool | 76f79ba | 2002-01-23 05:51:06 +0000 | [diff] [blame] | 151 | /* Safer to change it here than script */ |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 152 | /* |
| 153 | * Change to --read-batch=prefix |
| 154 | * to get ready for remote |
| 155 | */ |
| 156 | strlcat(buff, "--read-batch=", sizeof(buff)); |
| 157 | strlcat(buff, batch_prefix, sizeof(buff)); |
| 158 | } else |
| 159 | if (i == argc - 1) { |
| 160 | snprintf(buff2, sizeof(buff2), "${1:-%s}", argv[i]); |
| 161 | strlcat(buff, buff2, sizeof(buff)); |
| 162 | } |
| 163 | else { |
| Martin Pool | 76f79ba | 2002-01-23 05:51:06 +0000 | [diff] [blame] | 164 | strlcat(buff, argv[i], sizeof(buff)); |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | if (i < (argc - 1)) { |
| Martin Pool | 76f79ba | 2002-01-23 05:51:06 +0000 | [diff] [blame] | 168 | strlcat(buff, " ", sizeof(buff)); |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 169 | } |
| 170 | } |
| Martin Pool | 76f79ba | 2002-01-23 05:51:06 +0000 | [diff] [blame] | 171 | strlcat(buff, "\n", sizeof(buff)); |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 172 | if (!write(fdb, buff, strlen(buff))) { |
| 173 | rprintf(FERROR, "Batch file %s write error: %s\n", |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 174 | filename, strerror(errno)); |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 175 | close(fdb); |
| 176 | exit_cleanup(1); |
| 177 | } |
| 178 | close(fdb); |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 179 | } |
| 180 | |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 181 | struct file_list *create_flist_from_batch(void) |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 182 | { |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 183 | unsigned char flags; |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 184 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 185 | fdb_open = 1; |
| 186 | fdb_close = 0; |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 187 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 188 | batch_flist = (struct file_list *) malloc(sizeof(batch_flist[0])); |
| 189 | if (!batch_flist) { |
| 190 | out_of_memory("create_flist_from_batch"); |
| 191 | } |
| 192 | batch_flist->count = 0; |
| 193 | batch_flist->malloced = 1000; |
| 194 | batch_flist->files = |
| 195 | (struct file_struct **) malloc(sizeof(batch_flist->files[0]) * |
| 196 | batch_flist->malloced); |
| 197 | if (!batch_flist->files) { |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 198 | out_of_memory("create_flist_from_batch"); |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 199 | } |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 200 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 201 | for (flags = read_batch_flags(); flags; flags = read_batch_flags()) { |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 202 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 203 | int i = batch_flist->count; |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 204 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 205 | if (i >= batch_flist->malloced) { |
| 206 | if (batch_flist->malloced < 1000) |
| 207 | batch_flist->malloced += 1000; |
| 208 | else |
| 209 | batch_flist->malloced *= 2; |
| 210 | batch_flist->files = |
| 211 | (struct file_struct **) realloc(batch_flist-> |
| 212 | files, |
| 213 | sizeof |
| 214 | (batch_flist-> |
| 215 | files[0]) * |
| 216 | batch_flist-> |
| 217 | malloced); |
| 218 | if (!batch_flist->files) |
| 219 | out_of_memory("create_flist_from_batch"); |
| 220 | } |
| 221 | read_batch_flist_info(&batch_flist->files[i]); |
| 222 | batch_flist->files[i]->flags = flags; |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 223 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 224 | batch_flist->count++; |
| 225 | } |
| 226 | |
| 227 | return batch_flist; |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | int read_batch_flist_file(char *buff, int len) |
| 231 | { |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 232 | int bytes_read; |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 233 | char filename[MAXPATHLEN]; |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 234 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 235 | if (fdb_open) { |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 236 | /* Set up file extension */ |
| 237 | strlcpy(filename, batch_prefix, sizeof(filename)); |
| 238 | strlcat(filename, rsync_flist_file, sizeof(filename)); |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 239 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 240 | /* Open batch flist file for reading */ |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 241 | fdb = do_open(filename, O_RDONLY, 0); |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 242 | if (fdb == -1) { |
| 243 | rprintf(FERROR, "Batch file %s open error: %s\n", |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 244 | filename, strerror(errno)); |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 245 | close(fdb); |
| 246 | exit_cleanup(1); |
| 247 | } |
| 248 | fdb_open = 0; |
| 249 | } |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 250 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 251 | /* Read flist batch file */ |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 252 | |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 253 | switch (bytes_read = read(fdb, buff, len)) { |
| 254 | case -1: |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 255 | rprintf(FERROR, "Batch file %s read error: %s\n", |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 256 | filename, strerror(errno)); |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 257 | close(fdb); |
| 258 | exit_cleanup(1); |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 259 | break; |
| 260 | case 0: /* EOF */ |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 261 | close(fdb); |
| 262 | } |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 263 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 264 | return bytes_read; |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | unsigned char read_batch_flags() |
| 268 | { |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 269 | int flags; |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 270 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 271 | if (read_batch_flist_file((char *) &flags, 4)) { |
| 272 | return 1; |
| 273 | } else { |
| 274 | return 0; |
| 275 | } |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | void read_batch_flist_info(struct file_struct **fptr) |
| 279 | { |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 280 | int int_str_len; |
| 281 | char char_str_len[4]; |
| 282 | char buff[256]; |
| 283 | struct file_struct *file; |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 284 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 285 | file = (struct file_struct *) malloc(sizeof(*file)); |
| 286 | if (!file) |
| 287 | out_of_memory("read_batch_flist_info"); |
| 288 | memset((char *) file, 0, sizeof(*file)); |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 289 | |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 290 | *fptr = file; |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 291 | |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 292 | /* |
| 293 | * Keep these in sync with bytes_to_write assignment |
| 294 | * in write_batch_flist_info() |
| 295 | */ |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 296 | read_batch_flist_file((char *) &file->modtime, sizeof(time_t)); |
| 297 | read_batch_flist_file((char *) &file->length, sizeof(OFF_T)); |
| 298 | read_batch_flist_file((char *) &file->mode, sizeof(mode_t)); |
| Martin Pool | 6abd193 | 2002-01-11 08:25:32 +0000 | [diff] [blame] | 299 | read_batch_flist_file((char *) &file->inode, sizeof(INO64_T)); |
| 300 | read_batch_flist_file((char *) &file->dev, sizeof(DEV64_T)); |
| Martin Pool | 76f79ba | 2002-01-23 05:51:06 +0000 | [diff] [blame] | 301 | read_batch_flist_file((char *) &file->rdev, sizeof(DEV64_T)); |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 302 | read_batch_flist_file((char *) &file->uid, sizeof(uid_t)); |
| 303 | read_batch_flist_file((char *) &file->gid, sizeof(gid_t)); |
| 304 | read_batch_flist_file(char_str_len, sizeof(char_str_len)); |
| 305 | int_str_len = IVAL(char_str_len, 0); |
| 306 | if (int_str_len > 0) { |
| 307 | read_batch_flist_file(buff, int_str_len); |
| 308 | buff[int_str_len] = '\0'; |
| 309 | file->basename = strdup(buff); |
| 310 | } else { |
| 311 | file->basename = NULL; |
| 312 | } |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 313 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 314 | read_batch_flist_file(char_str_len, sizeof(char_str_len)); |
| 315 | int_str_len = IVAL(char_str_len, 0); |
| 316 | if (int_str_len > 0) { |
| 317 | read_batch_flist_file(buff, int_str_len); |
| 318 | buff[int_str_len] = '\0'; |
| 319 | file[0].dirname = strdup(buff); |
| 320 | } else { |
| 321 | file[0].dirname = NULL; |
| 322 | } |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 323 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 324 | read_batch_flist_file(char_str_len, sizeof(char_str_len)); |
| 325 | int_str_len = IVAL(char_str_len, 0); |
| 326 | if (int_str_len > 0) { |
| 327 | read_batch_flist_file(buff, int_str_len); |
| 328 | buff[int_str_len] = '\0'; |
| 329 | file[0].basedir = strdup(buff); |
| 330 | } else { |
| 331 | file[0].basedir = NULL; |
| 332 | } |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 333 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 334 | read_batch_flist_file(char_str_len, sizeof(char_str_len)); |
| 335 | int_str_len = IVAL(char_str_len, 0); |
| 336 | if (int_str_len > 0) { |
| 337 | read_batch_flist_file(buff, int_str_len); |
| 338 | buff[int_str_len] = '\0'; |
| 339 | file[0].link = strdup(buff); |
| 340 | } else { |
| 341 | file[0].link = NULL; |
| 342 | } |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 343 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 344 | read_batch_flist_file(char_str_len, sizeof(char_str_len)); |
| 345 | int_str_len = IVAL(char_str_len, 0); |
| 346 | if (int_str_len > 0) { |
| 347 | read_batch_flist_file(buff, int_str_len); |
| 348 | buff[int_str_len] = '\0'; |
| 349 | file[0].sum = strdup(buff); |
| 350 | } else { |
| 351 | file[0].sum = NULL; |
| 352 | } |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 353 | } |
| 354 | |
| Martin Pool | 55d9e0f | 2002-01-24 08:08:56 +0000 | [diff] [blame] | 355 | void write_batch_csums_file(void *buff, int bytes_to_write) |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 356 | { |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 357 | static int fdb_open = 1; |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 358 | char filename[MAXPATHLEN]; |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 359 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 360 | if (fdb_open) { |
| 361 | /* Set up file extension */ |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 362 | strlcpy(filename, batch_prefix, sizeof(filename)); |
| 363 | strlcat(filename, rsync_csums_file, sizeof(filename)); |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 364 | |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 365 | /* |
| 366 | * Open batch csums file for writing; |
| 367 | * create it if it doesn't exist |
| 368 | */ |
| 369 | fdb = do_open(filename, O_WRONLY | O_CREAT | O_TRUNC, |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 370 | S_IREAD | S_IWRITE); |
| 371 | if (fdb == -1) { |
| 372 | rprintf(FERROR, "Batch file %s open error: %s\n", |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 373 | filename, strerror(errno)); |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 374 | close(fdb); |
| 375 | exit_cleanup(1); |
| 376 | } |
| 377 | fdb_open = 0; |
| 378 | } |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 379 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 380 | /* Write buffer to batch csums file */ |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 381 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 382 | if (write(fdb, buff, bytes_to_write) == -1) { |
| 383 | rprintf(FERROR, "Batch file %s write error: %s\n", |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 384 | filename, strerror(errno)); |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 385 | close(fdb); |
| 386 | exit_cleanup(1); |
| 387 | } |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 388 | } |
| 389 | |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 390 | void close_batch_csums_file(void) |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 391 | { |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 392 | close(fdb); |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 393 | } |
| 394 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 395 | void write_batch_csum_info(int *flist_entry, int flist_count, |
| 396 | struct sum_struct *s) |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 397 | { |
| Martin Pool | 5664871 | 2002-01-24 08:09:46 +0000 | [diff] [blame] | 398 | size_t i; |
| Martin Pool | 935b920 | 2002-01-23 07:32:29 +0000 | [diff] [blame] | 399 | unsigned int int_zero = 0; |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 400 | extern int csum_length; |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 401 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 402 | fdb_open = 1; |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 403 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 404 | /* Write csum info to batch file */ |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 405 | |
| Martin Pool | 929e301 | 2002-01-24 08:07:35 +0000 | [diff] [blame] | 406 | /* FIXME: This will break if s->count is ever not exactly an int. */ |
| Martin Pool | 55d9e0f | 2002-01-24 08:08:56 +0000 | [diff] [blame] | 407 | write_batch_csums_file(flist_entry, sizeof(int)); |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 408 | write_batch_csums_file(s ? &s->count : &int_zero, sizeof(int)); |
| Martin Pool | 929e301 | 2002-01-24 08:07:35 +0000 | [diff] [blame] | 409 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 410 | if (s) { |
| 411 | for (i = 0; i < s->count; i++) { |
| Martin Pool | 55d9e0f | 2002-01-24 08:08:56 +0000 | [diff] [blame] | 412 | write_batch_csums_file(&s->sums[i].sum1, sizeof(uint32)); |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 413 | if ((*flist_entry == flist_count - 1) |
| 414 | && (i == s->count - 1)) { |
| 415 | fdb_close = 1; |
| 416 | } |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 417 | write_batch_csums_file(s->sums[i].sum2, csum_length); |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 418 | } |
| 419 | } |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | int read_batch_csums_file(char *buff, int len) |
| 423 | { |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 424 | static int fdb_open = 1; |
| 425 | int bytes_read; |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 426 | char filename[MAXPATHLEN]; |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 427 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 428 | if (fdb_open) { |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 429 | /* Set up file extension */ |
| 430 | strlcpy(filename, batch_prefix, sizeof(filename)); |
| 431 | strlcat(filename, rsync_csums_file, sizeof(filename)); |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 432 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 433 | /* Open batch flist file for reading */ |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 434 | fdb = do_open(filename, O_RDONLY, 0); |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 435 | if (fdb == -1) { |
| 436 | rprintf(FERROR, "Batch file %s open error: %s\n", |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 437 | filename, strerror(errno)); |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 438 | close(fdb); |
| 439 | exit_cleanup(1); |
| 440 | } |
| 441 | fdb_open = 0; |
| 442 | } |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 443 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 444 | /* Read csums batch file */ |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 445 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 446 | bytes_read = read(fdb, buff, len); |
| 447 | |
| 448 | if (bytes_read == -1) { |
| 449 | rprintf(FERROR, "Batch file %s read error: %s\n", |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 450 | filename, strerror(errno)); |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 451 | close(fdb); |
| 452 | exit_cleanup(1); |
| 453 | } |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 454 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 455 | return bytes_read; |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 456 | } |
| 457 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 458 | void read_batch_csum_info(int flist_entry, struct sum_struct *s, |
| 459 | int *checksums_match) |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 460 | { |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 461 | int i; |
| 462 | int file_flist_entry; |
| 463 | int file_chunk_ct; |
| 464 | uint32 file_sum1; |
| 465 | char file_sum2[SUM_LENGTH]; |
| 466 | extern int csum_length; |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 467 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 468 | read_batch_csums_file((char *) &file_flist_entry, sizeof(int)); |
| 469 | if (file_flist_entry != flist_entry) { |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 470 | rprintf(FINFO, "file_flist_entry (%d) != flist_entry (%d)\n", |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 471 | file_flist_entry, flist_entry); |
| 472 | close(fdb); |
| 473 | exit_cleanup(1); |
| 474 | |
| 475 | } else { |
| 476 | read_batch_csums_file((char *) &file_chunk_ct, |
| 477 | sizeof(int)); |
| 478 | *checksums_match = 1; |
| 479 | for (i = 0; i < file_chunk_ct; i++) { |
| 480 | |
| 481 | read_batch_csums_file((char *) &file_sum1, |
| 482 | sizeof(uint32)); |
| 483 | read_batch_csums_file(file_sum2, csum_length); |
| 484 | |
| 485 | if ((s->sums[i].sum1 != file_sum1) || |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 486 | (memcmp(s->sums[i].sum2, file_sum2, csum_length) |
| 487 | != 0)) { |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 488 | *checksums_match = 0; |
| 489 | } |
| 490 | } /* end for */ |
| 491 | } |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | void write_batch_delta_file(char *buff, int bytes_to_write) |
| 495 | { |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 496 | static int fdb_delta_open = 1; |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 497 | char filename[MAXPATHLEN]; |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 498 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 499 | if (fdb_delta_open) { |
| 500 | /* Set up file extension */ |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 501 | strlcpy(filename, batch_prefix, sizeof(filename)); |
| 502 | strlcat(filename, rsync_delta_file, sizeof(filename)); |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 503 | |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 504 | /* |
| 505 | * Open batch delta file for writing; |
| 506 | * create it if it doesn't exist |
| 507 | */ |
| 508 | fdb_delta = do_open(filename, O_WRONLY | O_CREAT | O_TRUNC, |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 509 | S_IREAD | S_IWRITE); |
| 510 | if (fdb_delta == -1) { |
| 511 | rprintf(FERROR, "Batch file %s open error: %s\n", |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 512 | filename, strerror(errno)); |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 513 | close(fdb_delta); |
| 514 | exit_cleanup(1); |
| 515 | } |
| 516 | fdb_delta_open = 0; |
| 517 | } |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 518 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 519 | /* Write buffer to batch delta file */ |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 520 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 521 | if (write(fdb_delta, buff, bytes_to_write) == -1) { |
| 522 | rprintf(FERROR, "Batch file %s write error: %s\n", |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 523 | filename, strerror(errno)); |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 524 | close(fdb_delta); |
| 525 | exit_cleanup(1); |
| 526 | } |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 527 | } |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 528 | |
| 529 | void close_batch_delta_file(void) |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 530 | { |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 531 | close(fdb_delta); |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | int read_batch_delta_file(char *buff, int len) |
| 535 | { |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 536 | static int fdb_delta_open = 1; |
| 537 | int bytes_read; |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 538 | char filename[MAXPATHLEN]; |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 539 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 540 | if (fdb_delta_open) { |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 541 | /* Set up file extension */ |
| 542 | strlcpy(filename, batch_prefix, sizeof(filename)); |
| 543 | strlcat(filename, rsync_delta_file, sizeof(filename)); |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 544 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 545 | /* Open batch flist file for reading */ |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 546 | fdb_delta = do_open(filename, O_RDONLY, 0); |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 547 | if (fdb_delta == -1) { |
| 548 | rprintf(FERROR, "Batch file %s open error: %s\n", |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 549 | filename, strerror(errno)); |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 550 | close(fdb_delta); |
| 551 | exit_cleanup(1); |
| 552 | } |
| 553 | fdb_delta_open = 0; |
| 554 | } |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 555 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 556 | /* Read delta batch file */ |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 557 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 558 | bytes_read = read(fdb_delta, buff, len); |
| 559 | |
| 560 | if (bytes_read == -1) { |
| 561 | rprintf(FERROR, "Batch file %s read error: %s\n", |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 562 | filename, strerror(errno)); |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 563 | close(fdb_delta); |
| 564 | exit_cleanup(1); |
| 565 | } |
| David Dykstra | 088aac8 | 2002-02-06 21:20:48 +0000 | [diff] [blame^] | 566 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 567 | return bytes_read; |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 568 | } |
| 569 | |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 570 | void show_flist(int index, struct file_struct **fptr) |
| 571 | { |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 572 | /* for debugging show_flist(flist->count, flist->files * */ |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 573 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 574 | int i; |
| 575 | for (i = 0; i < index; i++) { |
| 576 | rprintf(FINFO, "flist->flags=%#x\n", fptr[i]->flags); |
| 577 | rprintf(FINFO, "flist->modtime=%#lx\n", |
| 578 | (long unsigned) fptr[i]->modtime); |
| 579 | rprintf(FINFO, "flist->length=%.0f\n", |
| 580 | (double) fptr[i]->length); |
| 581 | rprintf(FINFO, "flist->mode=%#o\n", (int) fptr[i]->mode); |
| 582 | rprintf(FINFO, "flist->basename=%s\n", fptr[i]->basename); |
| 583 | if (fptr[i]->dirname) |
| 584 | rprintf(FINFO, "flist->dirname=%s\n", |
| 585 | fptr[i]->dirname); |
| 586 | if (fptr[i]->basedir) |
| 587 | rprintf(FINFO, "flist->basedir=%s\n", |
| 588 | fptr[i]->basedir); |
| 589 | } |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | void show_argvs(int argc, char *argv[]) |
| 593 | { |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 594 | /* for debugging * */ |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 595 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 596 | int i; |
| 597 | rprintf(FINFO, "BATCH.C:show_argvs,argc=%d\n", argc); |
| 598 | for (i = 0; i < argc; i++) { |
| 599 | /* if (argv[i]) */ |
| 600 | rprintf(FINFO, "i=%d,argv[i]=%s\n", i, argv[i]); |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 601 | |
| Martin Pool | 1cd5bee | 2001-12-02 22:28:50 +0000 | [diff] [blame] | 602 | } |
| Martin Pool | 6902ed1 | 2001-08-14 02:04:47 +0000 | [diff] [blame] | 603 | } |