- * list. If both are dirs, keep the last one.
- * Otherwise keep the first one. */
- if (S_ISDIR(file->mode))
- keep = i, drop = j;
- else
+ * list. Otherwise keep the first one. */
+ if (S_ISDIR(file->mode)) {
+ struct file_struct *fp = flist->sorted[j];
+ if (!S_ISDIR(fp->mode) || !(fp->flags & FLAG_XFER_DIR))
+ keep = i, drop = j;
+ else {
+ if (am_sender)
+ file->flags |= FLAG_DUPLICATE;
+ keep = j, drop = i;
+ }
+ } else