~ubuntu-branches/ubuntu/trusty/rsync/trusty

« back to all changes in this revision

Viewing changes to hlink.c

  • Committer: Package Import Robot
  • Author(s): Paul Slootman
  • Date: 2013-10-27 12:01:10 UTC
  • mfrom: (1.1.13) (2.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20131027120110-mpr03n5scqmf40mi
Tags: 3.1.0-2
fix build failure if zlib1g-dev package is not installed;
solved by building without the included zlib source and adding a
build-depends on zlib1g-dev >= 1:1.2.8
closes:32379

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 * Copyright (C) 1996 Andrew Tridgell
5
5
 * Copyright (C) 1996 Paul Mackerras
6
6
 * Copyright (C) 2002 Martin Pool <mbp@samba.org>
7
 
 * Copyright (C) 2004-2009 Wayne Davison
 
7
 * Copyright (C) 2004-2013 Wayne Davison
8
8
 *
9
9
 * This program is free software; you can redistribute it and/or modify
10
10
 * it under the terms of the GNU General Public License as published by
21
21
 */
22
22
 
23
23
#include "rsync.h"
 
24
#include "inums.h"
 
25
#include "ifuncs.h"
24
26
 
25
 
extern int verbose;
26
27
extern int dry_run;
27
28
extern int list_only;
28
29
extern int am_sender;
31
32
extern int link_dest;
32
33
extern int preserve_acls;
33
34
extern int preserve_xattrs;
34
 
extern int make_backups;
35
35
extern int protocol_version;
36
36
extern int remove_source_files;
37
37
extern int stdout_format_has_i;
71
71
        if (!dev_node || dev_node->key != dev+1) {
72
72
                /* We keep a separate hash table of inodes for every device. */
73
73
                dev_node = hashtable_find(dev_tbl, dev+1, 1);
74
 
                if (!(tbl = dev_node->data))
 
74
                if (!(tbl = dev_node->data)) {
75
75
                        tbl = dev_node->data = hashtable_create(512, 1);
 
76
                        if (DEBUG_GTE(HLINK, 3)) {
 
77
                                rprintf(FINFO,
 
78
                                    "[%s] created hashtable for dev %s\n",
 
79
                                    who_am_i(), big_num(dev));
 
80
                        }
 
81
                }
76
82
        } else
77
83
                tbl = dev_node->data;
78
84
 
206
212
}
207
213
 
208
214
static int maybe_hard_link(struct file_struct *file, int ndx,
209
 
                           const char *fname, int statret, stat_x *sxp,
 
215
                           char *fname, int statret, stat_x *sxp,
210
216
                           const char *oldname, STRUCT_STAT *old_stp,
211
217
                           const char *realname, int itemizing, enum logcode code)
212
218
{
218
224
                                        ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS,
219
225
                                        0, "");
220
226
                        }
221
 
                        if (verbose > 1 && maybe_ATTRS_REPORT)
 
227
                        if (INFO_GTE(NAME, 2) && maybe_ATTRS_REPORT)
222
228
                                rprintf(FCLIENT, "%s is uptodate\n", fname);
223
229
                        file->flags |= FLAG_HLINK_DONE;
224
230
                        return 0;
225
231
                }
226
 
                if (make_backups > 0) {
227
 
                        if (!make_backup(fname))
228
 
                                return -1;
229
 
                } else if (robust_unlink(fname)) {
230
 
                        rsyserr(FERROR_XFER, errno, "unlink %s failed",
231
 
                                full_fname(fname));
232
 
                        return -1;
233
 
                }
234
232
        }
235
233
 
236
 
        if (hard_link_one(file, fname, oldname, 0)) {
 
234
        if (atomic_create(file, fname, oldname, MAKEDEV(0, 0), sxp, statret == 0 ? DEL_FOR_FILE : 0)) {
237
235
                if (itemizing) {
238
236
                        itemize(fname, file, ndx, statret, sxp,
239
237
                                ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS, 0,
240
238
                                realname);
241
239
                }
242
 
                if (code != FNONE && verbose)
 
240
                if (code != FNONE && INFO_GTE(NAME, 1))
243
241
                        rprintf(code, "%s => %s\n", fname, realname);
244
242
                return 0;
245
243
        }
 
244
 
246
245
        return -1;
247
246
}
248
247
 
288
287
 
289
288
/* Only called if FLAG_HLINKED is set and FLAG_HLINK_FIRST is not.  Returns:
290
289
 * 0 = process the file, 1 = skip the file, -1 = error occurred. */
291
 
int hard_link_check(struct file_struct *file, int ndx, const char *fname,
 
290
int hard_link_check(struct file_struct *file, int ndx, char *fname,
292
291
                    int statret, stat_x *sxp, int itemizing,
293
292
                    enum logcode code)
294
293
{
307
306
                if (!flist) {
308
307
                        /* The previous file was skipped, so this one is
309
308
                         * treated as if it were the first in its group. */
 
309
                        if (DEBUG_GTE(HLINK, 2)) {
 
310
                                rprintf(FINFO, "hlink for %d (%s,%d): virtual first\n",
 
311
                                        ndx, f_name(file, NULL), gnum);
 
312
                        }
310
313
                        return 0;
311
314
                }
312
315
 
323
326
                                F_HL_PREV(prev_file) = ndx;
324
327
                                file->flags |= FLAG_FILE_SENT;
325
328
                                cur_flist->in_progress++;
 
329
                                if (DEBUG_GTE(HLINK, 2)) {
 
330
                                        rprintf(FINFO, "hlink for %d (%s,%d): waiting for %d\n",
 
331
                                                ndx, f_name(file, NULL), gnum, F_HL_PREV(file));
 
332
                                }
326
333
                                return 1;
327
334
                        }
 
335
                        if (DEBUG_GTE(HLINK, 2)) {
 
336
                                rprintf(FINFO, "hlink for %d (%s,%d): looking for a leader\n",
 
337
                                        ndx, f_name(file, NULL), gnum);
 
338
                        }
328
339
                        return 0;
329
340
                }
330
341
 
332
343
                if (!(prev_file->flags & FLAG_HLINK_FIRST)) {
333
344
                        /* The previous previous is FIRST when prev is not. */
334
345
                        prev_name = realname = check_prior(prev_file, gnum, &prev_ndx, &flist);
335
 
                        assert(prev_name != NULL || flist != NULL);
336
346
                        /* Update our previous pointer to point to the FIRST. */
337
347
                        F_HL_PREV(file) = prev_ndx;
338
348
                }
340
350
                if (!prev_name) {
341
351
                        int alt_dest;
342
352
 
 
353
                        assert(flist != NULL);
343
354
                        prev_file = flist->files[prev_ndx - flist->ndx_start];
344
355
                        /* F_HL_PREV() is alt_dest value when DONE && FIRST. */
345
356
                        alt_dest = F_HL_PREV(prev_file);
 
357
                        if (DEBUG_GTE(HLINK, 2)) {
 
358
                                rprintf(FINFO, "hlink for %d (%s,%d): found flist match (alt %d)\n",
 
359
                                        ndx, f_name(file, NULL), gnum, alt_dest);
 
360
                        }
346
361
 
347
362
                        if (alt_dest >= 0 && dry_run) {
348
363
                                pathjoin(namebuf, MAXPATHLEN, basis_dir[alt_dest],
356
371
                }
357
372
        }
358
373
 
 
374
        if (DEBUG_GTE(HLINK, 2)) {
 
375
                rprintf(FINFO, "hlink for %d (%s,%d): leader is %d (%s)\n",
 
376
                        ndx, f_name(file, NULL), gnum, prev_ndx, prev_name);
 
377
        }
 
378
 
359
379
        if (link_stat(prev_name, &prev_st, 0) < 0) {
360
380
                if (!dry_run || errno != ENOENT) {
361
381
                        rsyserr(FERROR_XFER, errno, "stat %s failed", full_fname(prev_name));
371
391
                char cmpbuf[MAXPATHLEN];
372
392
                stat_x alt_sx;
373
393
                int j = 0;
374
 
#ifdef SUPPORT_ACLS
375
 
                alt_sx.acc_acl = alt_sx.def_acl = NULL;
376
 
#endif
377
 
#ifdef SUPPORT_XATTRS
378
 
                alt_sx.xattr = NULL;
379
 
#endif
 
394
                init_stat_x(&alt_sx);
380
395
                do {
381
396
                        pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
382
397
                        if (link_stat(cmpbuf, &alt_sx.st, 0) < 0)
387
402
                                        continue;
388
403
                                statret = 1;
389
404
                                if (stdout_format_has_i == 0
390
 
                                 || (verbose < 2 && stdout_format_has_i < 2)) {
 
405
                                 || (!INFO_GTE(NAME, 2) && stdout_format_has_i < 2)) {
391
406
                                        itemizing = 0;
392
407
                                        code = FNONE;
393
 
                                        if (verbose > 1 && maybe_ATTRS_REPORT)
 
408
                                        if (INFO_GTE(NAME, 2) && maybe_ATTRS_REPORT)
394
409
                                                rprintf(FCLIENT, "%s is uptodate\n", fname);
395
410
                                }
396
411
                                break;
426
441
                                }
427
442
                        }
428
443
#endif
429
 
                } else {
430
 
#ifdef SUPPORT_ACLS
431
 
                        if (preserve_acls)
432
 
                                free_acl(&alt_sx);
433
 
#endif
434
 
#ifdef SUPPORT_XATTRS
435
 
                        if (preserve_xattrs)
436
 
                                free_xattr(&alt_sx);
437
 
#endif
438
 
                }
 
444
                } else
 
445
                        free_stat_x(&alt_sx);
439
446
        }
440
447
 
441
448
        if (maybe_hard_link(file, ndx, fname, statret, sxp, prev_name, &prev_st,
454
461
        if (do_link(oldname, fname) < 0) {
455
462
                enum logcode code;
456
463
                if (terse) {
457
 
                        if (!verbose)
 
464
                        if (!INFO_GTE(NAME, 1))
458
465
                                return 0;
459
466
                        code = FINFO;
460
467
                } else
481
488
        int prev_statret, ndx, prev_ndx = F_HL_PREV(file);
482
489
 
483
490
        if (stp == NULL && prev_ndx >= 0) {
484
 
                if (link_stat(fname, &st, 0) < 0) {
 
491
                if (link_stat(fname, &st, 0) < 0 && !dry_run) {
485
492
                        rsyserr(FERROR_XFER, errno, "stat %s failed",
486
493
                                full_fname(fname));
487
494
                        return;
499
506
        } else
500
507
                our_name = fname;
501
508
 
502
 
#ifdef SUPPORT_ACLS
503
 
        prev_sx.acc_acl = prev_sx.def_acl = NULL;
504
 
#endif
505
 
#ifdef SUPPORT_XATTRS
506
 
        prev_sx.xattr = NULL;
507
 
#endif
 
509
        init_stat_x(&prev_sx);
508
510
 
509
511
        while ((ndx = prev_ndx) >= 0) {
510
512
                int val;
517
519
                val = maybe_hard_link(file, ndx, prev_name, prev_statret, &prev_sx,
518
520
                                      our_name, stp, fname, itemizing, code);
519
521
                flist->in_progress--;
520
 
#ifdef SUPPORT_ACLS
521
 
                if (preserve_acls)
522
 
                        free_acl(&prev_sx);
523
 
#endif
524
 
#ifdef SUPPORT_XATTRS
525
 
                if (preserve_xattrs)
526
 
                        free_xattr(&prev_sx);
527
 
#endif
 
522
                free_stat_x(&prev_sx);
528
523
                if (val < 0)
529
524
                        continue;
530
525
                if (remove_source_files == 1 && do_xfers)