16 #include "mysys_priv.h"
19 #include "mysys_err.h"
20 #if defined(HAVE_UTIME_H)
22 #elif defined(HAVE_SYS_UTIME_H)
23 #include <sys/utime.h>
24 #elif !defined(HPUX10)
40 #define REDEL_EXT ".BAK"
42 int my_redel(
const char *org_name,
const char *tmp_name, myf MyFlags)
45 DBUG_ENTER(
"my_redel");
46 DBUG_PRINT(
"my",(
"org_name: '%s' tmp_name: '%s' MyFlags: %d",
47 org_name,tmp_name,MyFlags));
49 if (my_copystat(org_name,tmp_name,MyFlags) < 0)
51 if (MyFlags & MY_REDEL_MAKE_BACKUP)
53 char name_buff[FN_REFLEN+20];
56 get_date(ext+1,2+4,(time_t) 0);
57 strmov(strend(ext),REDEL_EXT);
58 if (my_rename(org_name, fn_format(name_buff, org_name,
"", ext, 2),
62 else if (my_delete_allow_opened(org_name, MyFlags))
64 if (my_rename(tmp_name,org_name,MyFlags))
76 int my_copystat(
const char *from,
const char *
to,
int MyFlags)
80 if (stat(from, &statbuf))
83 if (MyFlags & (MY_FAE+MY_WME))
85 char errbuf[MYSYS_STRERROR_SIZE];
86 my_error(EE_STAT, MYF(ME_BELL+ME_WAITTANG), from,
87 errno, my_strerror(errbuf,
sizeof(errbuf), errno));
91 if ((statbuf.st_mode & S_IFMT) != S_IFREG)
95 if (chmod(to, statbuf.st_mode & 07777))
98 if (MyFlags & (MY_FAE+MY_WME))
100 char errbuf[MYSYS_STRERROR_SIZE];
101 my_error(EE_CHANGE_PERMISSIONS, MYF(ME_BELL+ME_WAITTANG), from,
102 errno, my_strerror(errbuf,
sizeof(errbuf), errno));
107 #if !defined(__WIN__)
108 if (statbuf.st_nlink > 1 && MyFlags & MY_LINK_WARNING)
110 if (MyFlags & MY_LINK_WARNING)
111 my_error(EE_LINK_WARNING,MYF(ME_BELL+ME_WAITTANG),from,statbuf.st_nlink);
114 if (chown(to, statbuf.st_uid, statbuf.st_gid))
117 if (MyFlags & (MY_FAE+MY_WME))
119 char errbuf[MYSYS_STRERROR_SIZE];
120 my_error(EE_CHANGE_OWNERSHIP, MYF(ME_BELL+ME_WAITTANG), from,
121 errno, my_strerror(errbuf,
sizeof(errbuf), errno));
127 if (MyFlags & MY_COPYTIME)
130 timep.actime = statbuf.st_atime;
131 timep.modtime = statbuf.st_mtime;
132 (void) utime((
char*)
to, &timep);