- if ((p = strrchr(thisname,'/'))) {
- static char *lastdir;
- *p = 0;
- if (lastdir && strcmp(thisname, lastdir)==0) {
- file->dirname = lastdir;
- } else {
- file->dirname = strdup(thisname);
- lastdir = file->dirname;
+#if SUPPORT_LINKS
+ if (preserve_links && S_ISLNK(mode)) {
+ linkname_len = read_int(f) + 1; /* count the '\0' */
+ if (linkname_len <= 0 || linkname_len > MAXPATHLEN) {
+ rprintf(FERROR, "overflow: linkname_len=%d\n",
+ linkname_len - 1);
+ overflow("receive_file_entry");
+ }
+ }
+ else
+#endif
+ linkname_len = 0;
+
+ sum_len = always_checksum && S_ISREG(mode) ? MD4_SUM_LENGTH : 0;
+
+ alloc_len = file_struct_len + dirname_len + basename_len
+ + linkname_len + sum_len;
+ bp = pool_alloc(flist->file_pool, alloc_len, "receive_file_entry");
+
+ file = flist->files[ndx] = (struct file_struct *)bp;
+ memset(bp, 0, file_struct_len);
+ bp += file_struct_len;
+
+ file->flags = 0;
+ file->modtime = modtime;
+ file->length = file_length;
+ file->mode = mode;
+ file->uid = uid;
+ file->gid = gid;
+
+ if (dirname_len) {
+ file->dirname = lastdir = bp;
+ lastdir_len = dirname_len - 1;
+ memcpy(bp, dirname, dirname_len - 1);
+ bp += dirname_len;
+ bp[-1] = '\0';
+ lastdir_depth = count_dir_elements(lastdir);
+ file->dir.depth = lastdir_depth + 1;
+ } else if (dirname) {
+ file->dirname = dirname; /* we're reusing lastname */
+ file->dir.depth = lastdir_depth + 1;
+ } else
+ file->dir.depth = 1;
+
+ if (S_ISDIR(mode)) {
+ if (basename_len == 1+1 && *basename == '.') /* N.B. null */
+ file->dir.depth--;
+ if (flags & XMIT_DEL_START) {
+ in_del_hier = 1;
+ del_hier_name_len = file->dir.depth == 0 ? 0 : l1 + l2;
+ file->flags |= FLAG_DEL_START;
+ } else if (delete_during && in_del_hier) {
+ if (!relative_paths || !del_hier_name_len
+ || (l1 >= del_hier_name_len
+ && thisname[del_hier_name_len] == '/'))
+ file->flags |= FLAG_DEL_START;
+ else
+ in_del_hier = 0;