00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <config.h>
00017
00018 #include <drizzled/internal/my_sys.h>
00019 #include <drizzled/internal/m_string.h>
00020 #include <drizzled/error.h>
00021 #if defined(HAVE_UTIME_H)
00022 #include <utime.h>
00023 #elif defined(HAVE_SYS_UTIME_H)
00024 #include <sys/utime.h>
00025 #elif !defined(HPUX10)
00026 struct utimbuf {
00027 time_t actime;
00028 time_t modtime;
00029 };
00030 #endif
00031 #ifdef HAVE_SYS_STAT_H
00032 # include <sys/stat.h>
00033 #endif
00034
00035 namespace drizzled
00036 {
00037 namespace internal
00038 {
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 #define REDEL_EXT ".BAK"
00050
00051 int my_redel(const char *org_name, const char *tmp_name, myf MyFlags)
00052 {
00053 int error=1;
00054
00055 if (my_copystat(org_name,tmp_name,MyFlags) < 0)
00056 goto end;
00057 if (MyFlags & MY_REDEL_MAKE_BACKUP)
00058 {
00059 char name_buff[FN_REFLEN+20];
00060 char ext[20];
00061 ext[0]='-';
00062 get_date(ext+1,2+4,(time_t) 0);
00063 strcpy(strchr(ext, '\0'),REDEL_EXT);
00064 if (my_rename(org_name, fn_format(name_buff, org_name, "", ext, 2),
00065 MyFlags))
00066 goto end;
00067 }
00068 else if (my_delete(org_name, MyFlags))
00069 goto end;
00070 if (my_rename(tmp_name,org_name,MyFlags))
00071 goto end;
00072
00073 error=0;
00074 end:
00075 return(error);
00076 }
00077
00078
00079
00080
00081
00082 int my_copystat(const char *from, const char *to, int MyFlags)
00083 {
00084 struct stat statbuf;
00085
00086 if (stat((char*) from, &statbuf))
00087 {
00088 errno=errno;
00089 if (MyFlags & (MY_FAE+MY_WME))
00090 my_error(EE_STAT, MYF(ME_BELL+ME_WAITTANG),from,errno);
00091 return -1;
00092 }
00093 if ((statbuf.st_mode & S_IFMT) != S_IFREG)
00094 return 1;
00095 chmod(to, statbuf.st_mode & 07777);
00096
00097 if (statbuf.st_nlink > 1 && MyFlags & MY_LINK_WARNING)
00098 {
00099 if (MyFlags & MY_LINK_WARNING)
00100 my_error(EE_LINK_WARNING,MYF(ME_BELL+ME_WAITTANG),from,statbuf.st_nlink);
00101 }
00102 if(chown(to, statbuf.st_uid, statbuf.st_gid)!=0)
00103 return 1;
00104
00105 #ifndef __ZTC__
00106 if (MyFlags & MY_COPYTIME)
00107 {
00108 struct utimbuf timep;
00109 timep.actime = statbuf.st_atime;
00110 timep.modtime = statbuf.st_mtime;
00111 utime((char*) to, &timep);
00112 }
00113 #else
00114 if (MyFlags & MY_COPYTIME)
00115 {
00116 time_t time[2];
00117 time[0]= statbuf.st_atime;
00118 time[1]= statbuf.st_mtime;
00119 utime((char*) to, time);
00120 }
00121 #endif
00122 return 0;
00123 }
00124
00125 }
00126 }