84 const char *cgName,
const char *anchor)
87 const int AMode = S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH;
93 pendFiles(
char *pb,
char *tb) : datfd(-1)
94 {pbuff = pb; *pb =
'\0';
95 tbuff = tb; *tb =
'\0';
97 ~pendFiles() {
if (datfd >= 0)
close(datfd);
98 if (pbuff && *pbuff)
unlink(pbuff);
99 if (tbuff && *tbuff)
unlink(tbuff);
103 char lbuff[MAXPATHLEN+8];
104 char pbuff[MAXPATHLEN+8];
105 char tbuff[MAXPATHLEN+8];
106 char local_path[MAXPATHLEN+8];
107 pendFiles PF(pbuff, tbuff);
109 int rc, lblen, datfd, Pure = (anchor && !strcmp(anchor,
"."));
115 if (Pure) {strcpy(local_path, path); anchor = 0;}
116 else if ((rc =
GenLocalPath(path, local_path)))
return rc;
120 if (
stat(local_path, &buf))
return -errno;
121 if ((buf.st_mode & S_IFMT) == S_IFDIR)
return -EISDIR;
122 if ((buf.st_mode & S_IFMT) != S_IFREG)
return -ENOTBLK;
133 if (!Pure && !strcmp(cgbuff, cgNow)
140 aInfo.
cgSize = (Pure ? 0 : buf.st_size);
143 if (!aInfo.
cgPsfx)
return -ENOTSUP;
148 if ((rc_c =
XrdOssCopy::Copy(local_path, pbuff, datfd)) < 0)
return (
int)rc_c;
152 if (!anchor) {strcpy(tbuff, local_path); strcat(tbuff,
".anew");}
153 else {
struct stat sbuf;
155 if (strlen(anchor)+strlen(path) >=
sizeof(local_path))
156 return -ENAMETOOLONG;
157 strcpy(local_path, anchor); strcat(local_path, path);
158 if (!(Slash = rindex(local_path,
'/')))
return -ENOTDIR;
159 *Slash =
'\0'; rc =
stat(local_path, &sbuf); *Slash =
'/';
162 strcpy(tbuff, local_path);
167 if ((symlink(pbuff, tbuff) && errno != EEXIST)
168 ||
unlink(tbuff) || symlink(pbuff, tbuff))
return -errno;
172 if (!anchor &&
rename(tbuff, local_path) < 0)
return -errno;
173 PF.tbuff = 0; PF.pbuff = 0; rc = 0;
178 if (rc)
OssEroute.
Emsg(
"Reloc", rc,
"create symlink", pbuff);
183 DEBUG(cgNow <<
':' <<local_path <<
" -> " <<aInfo.
cgName <<
':' <<pbuff);