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 int my_redel(const char *org_name, const char *tmp_name, myf MyFlags)
00050 {
00051 int error=1;
00052
00053 if (my_copystat(org_name,tmp_name,MyFlags) < 0)
00054 goto end;
00055 if (my_delete(org_name, MyFlags))
00056 goto end;
00057 if (my_rename(tmp_name,org_name,MyFlags))
00058 goto end;
00059
00060 error=0;
00061 end:
00062 return(error);
00063 }
00064
00065
00066
00067
00068
00069 int my_copystat(const char *from, const char *to, int MyFlags)
00070 {
00071 struct stat statbuf;
00072
00073 if (stat((char*) from, &statbuf))
00074 {
00075 errno=errno;
00076 if (MyFlags & (MY_FAE+MY_WME))
00077 my_error(EE_STAT, MYF(ME_BELL+ME_WAITTANG),from,errno);
00078 return -1;
00079 }
00080 if ((statbuf.st_mode & S_IFMT) != S_IFREG)
00081 return 1;
00082 chmod(to, statbuf.st_mode & 07777);
00083
00084 if (statbuf.st_nlink > 1 && MyFlags & MY_LINK_WARNING)
00085 {
00086 if (MyFlags & MY_LINK_WARNING)
00087 my_error(EE_LINK_WARNING,MYF(ME_BELL+ME_WAITTANG),from,statbuf.st_nlink);
00088 }
00089 if(chown(to, statbuf.st_uid, statbuf.st_gid)!=0)
00090 return 1;
00091
00092 #ifndef __ZTC__
00093 if (MyFlags & MY_COPYTIME)
00094 {
00095 struct utimbuf timep;
00096 timep.actime = statbuf.st_atime;
00097 timep.modtime = statbuf.st_mtime;
00098 utime((char*) to, &timep);
00099 }
00100 #else
00101 if (MyFlags & MY_COPYTIME)
00102 {
00103 time_t time[2];
00104 time[0]= statbuf.st_atime;
00105 time[1]= statbuf.st_mtime;
00106 utime((char*) to, time);
00107 }
00108 #endif
00109 return 0;
00110 }
00111
00112 }
00113 }