+static bool
+handleDirEntry(const PathInfo *src_path, const PathInfo *basename,
+ bool *is_dir, struct stat *st)
+{
+ bool res = false;
+
+ *is_dir = false;
+
+ if (lstat(basename->d, st)==-1)
+ PERROR_Q(ENSC_WRAPPERS_PREFIX "lstat", src_path->d);
+ else {
+ PathInfo dst_path = global_info.dst;
+ char dst_path_buf[ENSC_PI_APPSZ(dst_path, *src_path)];
+
+ if (S_ISDIR(st->st_mode))
+ *is_dir = true;
+
+ if (MatchList_compare(&global_info.excludes, src_path->d) != stINCLUDE) {
+ if (Global_getVerbosity() > 1) {
+ WRITE_MSG(1, " skipping '");
+ Vwrite(1, src_path->d, src_path->l);
+ WRITE_MSG(1, "' (excluded)\n");
+ }
+ return false;
+ }
+
+ PathInfo_append(&dst_path, src_path, dst_path_buf);
+
+ /* skip files that already exist */
+ if (access(dst_path.d, F_OK)!=-1) {
+ if (Global_getVerbosity() > 1) {
+ WRITE_MSG(1, " skipping '");
+ Vwrite(1, src_path->d, src_path->l);
+ WRITE_MSG(1, "' (exists in destination)\n");
+ }
+ res = true;
+ }
+ else {
+ /* create directory that might have been skipped */
+ if (global_info.excludes.skip_depth > 0) {
+ if (Global_getVerbosity() > 4) {
+ WRITE_MSG(1, " creating directories for '");
+ Vwrite(1, dst_path.d, dst_path.l);
+ WRITE_MSG(1, "'\n");
+ }
+ if (mkdirRecursive(dst_path.d) == -1)
+ PERROR_Q(ENSC_WRAPPERS_PREFIX "mkdirRecursive", dst_path.d);
+ }
+
+ /* already unified file */
+ if (S_ISREG(st->st_mode) && Unify_isIUnlinkable(basename->d) == unifyBUSY) {
+ if (Global_getVerbosity() > 2) {
+ WRITE_MSG(1, " linking unified file '");
+ Vwrite(1, src_path->d, src_path->l);
+ WRITE_MSG(1, "'\n");
+ }
+ Elink(basename->d, dst_path.d);
+ res = true;
+ }
+ /* something we have to copy */
+ else {
+ if (Global_getVerbosity() > 2) {
+ WRITE_MSG(1, " copying non-unified file '");
+ Vwrite(1, src_path->d, src_path->l);
+ WRITE_MSG(1, "'\n");
+ }
+ if (!Unify_copy(basename->d, st, dst_path.d))
+ PERROR_Q(ENSC_WRAPPERS_PREFIX "Unify_copy", dst_path.d);
+ else if (global_args->xid != VC_NOCTX &&
+ vc_set_iattr(dst_path.d, global_args->xid, 0, VC_IATTR_XID) == -1)
+ PERROR_Q(ENSC_WRAPPERS_PREFIX "vc_set_iattr", dst_path.d);
+ else
+ res = true;
+ }
+ }
+ }
+
+ return res;
+}
+
+/* returns 1 on error, 0 on success */