~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000 MySQL AB
2
3
   This program is free software; you can redistribute it and/or modify
4
   it under the terms of the GNU General Public License as published by
5
   the Free Software Foundation; version 2 of the License.
6
7
   This program is distributed in the hope that it will be useful,
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
   GNU General Public License for more details.
11
12
   You should have received a copy of the GNU General Public License
13
   along with this program; if not, write to the Free Software
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
994.2.4 by Monty Taylor
Blast. Fixed some make distcheck issues.
16
#include "mysys/mysys_priv.h"
212.5.18 by Monty Taylor
Moved m_ctype, m_string and my_bitmap. Removed t_ctype.
17
#include <mystrings/m_string.h>
994.2.4 by Monty Taylor
Blast. Fixed some make distcheck issues.
18
#include "mysys/mysys_err.h"
1 by brian
clean slate
19
#if defined(HAVE_UTIME_H)
20
#include <utime.h>
21
#elif defined(HAVE_SYS_UTIME_H)
22
#include <sys/utime.h>
23
#elif !defined(HPUX10)
24
struct utimbuf {
25
  time_t actime;
26
  time_t modtime;
27
};
28
#endif
29
30
	/*
31
	  Rename with copy stat form old file
32
	  Copy stats from old file to new file, deletes orginal and
33
	  changes new file name to old file name
34
35
	  if MY_REDEL_MAKE_COPY is given, then the orginal file
36
	  is renamed to org_name-'current_time'.BAK
37
	*/
38
39
#define REDEL_EXT ".BAK"
40
41
int my_redel(const char *org_name, const char *tmp_name, myf MyFlags)
42
{
43
  int error=1;
44
45
  if (my_copystat(org_name,tmp_name,MyFlags) < 0)
46
    goto end;
47
  if (MyFlags & MY_REDEL_MAKE_BACKUP)
48
  {
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
49
    char name_buff[FN_REFLEN+20];
1 by brian
clean slate
50
    char ext[20];
51
    ext[0]='-';
52
    get_date(ext+1,2+4,(time_t) 0);
641.4.1 by Toru Maesaka
First pass of replacing MySQL's my_stpcpy() with appropriate libc calls
53
    strcpy(strchr(ext, '\0'),REDEL_EXT);
1 by brian
clean slate
54
    if (my_rename(org_name, fn_format(name_buff, org_name, "", ext, 2),
55
		  MyFlags))
56
      goto end;
57
  }
58
  else if (my_delete_allow_opened(org_name, MyFlags))
59
      goto end;
60
  if (my_rename(tmp_name,org_name,MyFlags))
61
    goto end;
62
63
  error=0;
64
end:
51.3.18 by Jay Pipes
Phase 5 - Remove DBUG from mysys
65
  return(error);
1 by brian
clean slate
66
} /* my_redel */
67
68
69
	/* Copy stat from one file to another */
70
	/* Return -1 if can't get stat, 1 if wrong type of file */
71
72
int my_copystat(const char *from, const char *to, int MyFlags)
73
{
74
  struct stat statbuf;
75
76
  if (stat((char*) from, &statbuf))
77
  {
78
    my_errno=errno;
79
    if (MyFlags & (MY_FAE+MY_WME))
80
      my_error(EE_STAT, MYF(ME_BELL+ME_WAITTANG),from,errno);
81
    return -1;				/* Can't get stat on input file */
82
  }
83
  if ((statbuf.st_mode & S_IFMT) != S_IFREG)
84
    return 1;
398.1.10 by Monty Taylor
Actually removed VOID() this time.
85
  chmod(to, statbuf.st_mode & 07777);		/* Copy modes */
1 by brian
clean slate
86
87
  if (statbuf.st_nlink > 1 && MyFlags & MY_LINK_WARNING)
88
  {
89
    if (MyFlags & MY_LINK_WARNING)
90
      my_error(EE_LINK_WARNING,MYF(ME_BELL+ME_WAITTANG),from,statbuf.st_nlink);
91
  }
512.1.1 by Stewart Smith
a few warnings that show up on ubuntu 8.10: unchecked return codes, not fromat string
92
  if(chown(to, statbuf.st_uid, statbuf.st_gid)!=0)
93
    return 1;
1 by brian
clean slate
94
95
#ifndef __ZTC__
96
  if (MyFlags & MY_COPYTIME)
97
  {
98
    struct utimbuf timep;
99
    timep.actime  = statbuf.st_atime;
100
    timep.modtime = statbuf.st_mtime;
398.1.10 by Monty Taylor
Actually removed VOID() this time.
101
    utime((char*) to, &timep);/* Update last accessed and modified times */
1 by brian
clean slate
102
  }
103
#else
104
  if (MyFlags & MY_COPYTIME)
105
  {
106
    time_t time[2];
107
    time[0]= statbuf.st_atime;
108
    time[1]= statbuf.st_mtime;
398.1.10 by Monty Taylor
Actually removed VOID() this time.
109
    utime((char*) to, time);/* Update last accessed and modified times */
1 by brian
clean slate
110
  }
111
#endif
112
  return 0;
113
} /* my_copystat */