version 1.25, 2019/05/08 20:00:25 |
version 1.26, 2019/05/08 21:30:11 |
|
|
* Returns zero on failure, non-zero on success. |
* Returns zero on failure, non-zero on success. |
*/ |
*/ |
static int |
static int |
flist_dedupe(struct sess *sess, struct flist **fl, size_t *sz) |
flist_dedupe(struct flist **fl, size_t *sz) |
{ |
{ |
size_t i, j; |
size_t i, j; |
struct flist *new; |
struct flist *new; |
|
|
*/ |
*/ |
|
|
if (sess->mplex_reads && |
if (sess->mplex_reads && |
io_read_check(sess, fdin) && |
io_read_check(fdin) && |
!io_read_flush(sess, fdin)) { |
!io_read_flush(sess, fdin)) { |
ERRX1("io_read_flush"); |
ERRX1("io_read_flush"); |
goto out; |
goto out; |
|
|
ERRX1("io_write_uint"); |
ERRX1("io_write_uint"); |
goto out; |
goto out; |
} |
} |
if (!idents_add(sess, 0, &uids, &uidsz, f->st.uid)) { |
if (!idents_add(0, &uids, &uidsz, f->st.uid)) { |
ERRX1("idents_add"); |
ERRX1("idents_add"); |
goto out; |
goto out; |
} |
} |
|
|
ERRX1("io_write_uint"); |
ERRX1("io_write_uint"); |
goto out; |
goto out; |
} |
} |
if (!idents_add(sess, 1, &gids, &gidsz, f->st.gid)) { |
if (!idents_add(1, &gids, &gidsz, f->st.gid)) { |
ERRX1("idents_add"); |
ERRX1("idents_add"); |
goto out; |
goto out; |
} |
} |
|
|
* Returns zero on failure, non-zero on success. |
* Returns zero on failure, non-zero on success. |
*/ |
*/ |
static int |
static int |
flist_realloc(struct sess *sess, struct flist **fl, size_t *sz, size_t *max) |
flist_realloc(struct flist **fl, size_t *sz, size_t *max) |
{ |
{ |
void *pp; |
void *pp; |
|
|
|
|
* Returns zero on failure, non-zero on success. |
* Returns zero on failure, non-zero on success. |
*/ |
*/ |
static int |
static int |
flist_append(struct sess *sess, struct flist *f, struct stat *st, |
flist_append(struct flist *f, struct stat *st, const char *path) |
const char *path) |
|
{ |
{ |
|
|
/* |
/* |
|
|
/* Optionally copy link information. */ |
/* Optionally copy link information. */ |
|
|
if (S_ISLNK(st->st_mode)) { |
if (S_ISLNK(st->st_mode)) { |
f->link = symlink_read(sess, f->path); |
f->link = symlink_read(f->path); |
if (f->link == NULL) { |
if (f->link == NULL) { |
ERRX1("symlink_read"); |
ERRX1("symlink_read"); |
return 0; |
return 0; |
|
|
} else if (flag == 0) |
} else if (flag == 0) |
break; |
break; |
|
|
if (!flist_realloc(sess, &fl, &flsz, &flmax)) { |
if (!flist_realloc(&fl, &flsz, &flmax)) { |
ERRX1("flist_realloc"); |
ERRX1("flist_realloc"); |
goto out; |
goto out; |
} |
} |
|
|
ERR("%s: lstat", root); |
ERR("%s: lstat", root); |
return 0; |
return 0; |
} else if (S_ISREG(st.st_mode)) { |
} else if (S_ISREG(st.st_mode)) { |
if (!flist_realloc(sess, fl, sz, max)) { |
if (!flist_realloc(fl, sz, max)) { |
ERRX1("flist_realloc"); |
ERRX1("flist_realloc"); |
return 0; |
return 0; |
} |
} |
f = &(*fl)[(*sz) - 1]; |
f = &(*fl)[(*sz) - 1]; |
assert(f != NULL); |
assert(f != NULL); |
|
|
if (!flist_append(sess, f, &st, root)) { |
if (!flist_append(f, &st, root)) { |
ERRX1("flist_append"); |
ERRX1("flist_append"); |
return 0; |
return 0; |
} |
} |
|
|
if (!sess->opts->preserve_links) { |
if (!sess->opts->preserve_links) { |
WARNX("%s: skipping symlink", root); |
WARNX("%s: skipping symlink", root); |
return 1; |
return 1; |
} else if (!flist_realloc(sess, fl, sz, max)) { |
} else if (!flist_realloc(fl, sz, max)) { |
ERRX1("flist_realloc"); |
ERRX1("flist_realloc"); |
return 0; |
return 0; |
} |
} |
f = &(*fl)[(*sz) - 1]; |
f = &(*fl)[(*sz) - 1]; |
assert(f != NULL); |
assert(f != NULL); |
|
|
if (!flist_append(sess, f, &st, root)) { |
if (!flist_append(f, &st, root)) { |
ERRX1("flist_append"); |
ERRX1("flist_append"); |
return 0; |
return 0; |
} |
} |
|
|
|
|
/* Allocate a new file entry. */ |
/* Allocate a new file entry. */ |
|
|
if (!flist_realloc(sess, fl, sz, max)) { |
if (!flist_realloc(fl, sz, max)) { |
ERRX1("flist_realloc"); |
ERRX1("flist_realloc"); |
goto out; |
goto out; |
} |
} |
|
|
/* Optionally copy link information. */ |
/* Optionally copy link information. */ |
|
|
if (S_ISLNK(ent->fts_statp->st_mode)) { |
if (S_ISLNK(ent->fts_statp->st_mode)) { |
f->link = symlink_read(sess, f->path); |
f->link = symlink_read(f->path); |
if (f->link == NULL) { |
if (f->link == NULL) { |
ERRX1("symlink_read"); |
ERRX1("symlink_read"); |
goto out; |
goto out; |
|
|
ERR("%s: unveil", argv[i]); |
ERR("%s: unveil", argv[i]); |
goto out; |
goto out; |
} |
} |
if (!flist_append(sess, f, &st, argv[i])) { |
if (!flist_append(f, &st, argv[i])) { |
ERRX1("flist_append"); |
ERRX1("flist_append"); |
goto out; |
goto out; |
} |
} |
|
|
|
|
qsort(*flp, *sz, sizeof(struct flist), flist_cmp); |
qsort(*flp, *sz, sizeof(struct flist), flist_cmp); |
|
|
if (flist_dedupe(sess, flp, sz)) { |
if (flist_dedupe(flp, sz)) { |
flist_topdirs(sess, *flp, *sz); |
flist_topdirs(sess, *flp, *sz); |
return 1; |
return 1; |
} |
} |
|
|
|
|
/* Not found: we'll delete it. */ |
/* Not found: we'll delete it. */ |
|
|
if (!flist_realloc(sess, fl, sz, &max)) { |
if (!flist_realloc(fl, sz, &max)) { |
ERRX1("flist_realloc"); |
ERRX1("flist_realloc"); |
goto out; |
goto out; |
} |
} |