37 #include <sys/param.h>
38 #include <sys/types.h>
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;
193 if (!
lstat(newlnk, &statbuff))
194 {
OssEroute.
Emsg(
"RenameLink",-EEXIST,
"check new target", newlnk);
200 if (symlink(newlnk, new_path))
208 if (
rename(oldlnk, newlnk))
236 strlen(new_path)+1, cPath)))
return rc;
240 if (!
rename(old_path, new_path))
return 0;
#define Check_RO(act, flags, path, opname)
int stat(const char *path, struct stat *buf)
int lstat(const char *path, struct stat *buf)
int unlink(const char *path)
int rename(const char *oldpath, const char *newpath)
static const char * Name()
static void Adjust(dev_t devid, off_t size)
static int Convert(char *dst, int dln, const char *oldP, const char *newP)
static void Trim2Base(char *eP)
int GenRemotePath(const char *, char *)
int MSS_Rename(const char *, const char *)
int RenameLink3(char *cPath, char *old_path, char *new_path)
int Rename(const char *, const char *, XrdOucEnv *eP1=0, XrdOucEnv *eP2=0)
int GenLocalPath(const char *, char *)
int RenameLink(char *old_path, char *new_path)
static int makePath(char *path, mode_t mode, bool reset=false)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
virtual int Set(const char *Aname, const void *Aval, int Avsz, const char *Path, int fd=-1, int isNew=0)=0