78 static const mode_t pMode = S_IRWXU | S_IRWXG;
79 unsigned long long remotefs_Old, remotefs_New, remotefs;
80 unsigned long long old_popts, new_popts;
83 char *slashPlus, sPChar;
84 char local_path_Old[MAXPATHLEN+8];
85 char local_path_New[MAXPATHLEN+8];
86 char remote_path_Old[MAXPATHLEN+1];
87 char remote_path_New[MAXPATHLEN+1];
96 if (remotefs_Old ^ remotefs_New
98 {
char buff[MAXPATHLEN+128];
99 snprintf(buff,
sizeof(buff),
"rename %s to ", oldname);
102 remotefs = remotefs_Old | remotefs_New;
107 || (retc =
GenLocalPath( newname, local_path_New)) )
return retc;
110 || (retc =
GenRemotePath(newname, remote_path_New)))) )
return retc;
114 if (!(retc2 = lstat(local_path_New, &statbuff)))
115 {
if (remotefs || (statbuff.st_mode & S_IFMT) == S_IFLNK)
return -EEXIST;
120 if (!(slashPlus = rindex(local_path_New,
'/')))
return -EINVAL;
121 slashPlus++; sPChar = *slashPlus; *slashPlus =
'\0';
124 if (retc2)
return retc2;
128 if (lstat(local_path_Old, &statbuff)) retc = -errno;
129 else if ((statbuff.st_mode & S_IFMT) == S_IFLNK)
130 retc =
RenameLink(local_path_Old, local_path_New);
131 else if (
rename(local_path_Old, local_path_New)) retc = -errno;
132 DEBUG(
"lcl rc=" <<retc <<
" op=" <<local_path_Old <<
" np=" <<local_path_New);
138 {
if (remotefs && (!retc || retc == -ENOENT) &&
RSSCmd)
139 {
if ( (retc2 =
MSS_Rename(remote_path_Old, remote_path_New))
140 != -ENOENT) retc = retc2;
141 DEBUG(
"rmt rc=" <<retc2 <<
" op=" <<remote_path_Old <<
" np=" <<remote_path_New);
159 struct stat statbuff;
160 char oldlnk[MAXPATHLEN+32], newlnk[MAXPATHLEN+32];
161 int lnklen, n, rc = 0;
165 if ((lnklen = readlink(old_path,oldlnk,
sizeof(oldlnk)-1)) < 0)
return -errno;
166 oldlnk[lnklen] =
'\0';
175 {n = strlen(old_path);
176 if (n < 6 || strcmp(old_path+n-5,
".anew")
177 ||
stat(new_path, &statbuff) || !statbuff.st_size)
return 0;
187 {
OssEroute.Emsg(
"RenameLink", rc,
"convert", oldlnk);
193 if (!lstat(newlnk, &statbuff))
194 {
OssEroute.Emsg(
"RenameLink",-EEXIST,
"check new target", newlnk);
200 if (symlink(newlnk, new_path))
202 OssEroute.Emsg(
"RenameLink", rc,
"symlink to", newlnk);
208 if (
rename(oldlnk, newlnk))
210 OssEroute.Emsg(
"RenameLink", rc,
"rename", oldlnk);
218 OssEroute.Emsg(
"RenameLink", rc,
"unlink", old_path);