~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
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
16
#include "config.h"
17
18
#include "drizzled/internal/my_sys.h"
1241.9.64 by Monty Taylor
Moved remaining non-public portions of mysys and mystrings to drizzled/internal.
19
#include "drizzled/internal/m_string.h"
1271.5.3 by Tim Penhey
change the include files
20
#include "drizzled/error.h"
1 by brian
clean slate
21
#if defined(HAVE_UTIME_H)
22
#include <utime.h>
23
#elif defined(HAVE_SYS_UTIME_H)
24
#include <sys/utime.h>
25
#elif !defined(HPUX10)
26
struct utimbuf {
27
  time_t actime;
28
  time_t modtime;
29
};
30
#endif
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
31
#ifdef HAVE_SYS_STAT_H
32
# include <sys/stat.h>
33
#endif
1 by brian
clean slate
34
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
35
namespace drizzled
36
{
37
namespace internal
38
{
39
1 by brian
clean slate
40
	/*
41
	  Rename with copy stat form old file
42
	  Copy stats from old file to new file, deletes orginal and
43
	  changes new file name to old file name
44
45
	  if MY_REDEL_MAKE_COPY is given, then the orginal file
46
	  is renamed to org_name-'current_time'.BAK
47
	*/
48
49
#define REDEL_EXT ".BAK"
50
51
int my_redel(const char *org_name, const char *tmp_name, myf MyFlags)
52
{
53
  int error=1;
54
55
  if (my_copystat(org_name,tmp_name,MyFlags) < 0)
56
    goto end;
57
  if (MyFlags & MY_REDEL_MAKE_BACKUP)
58
  {
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
59
    char name_buff[FN_REFLEN+20];
1 by brian
clean slate
60
    char ext[20];
61
    ext[0]='-';
62
    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
63
    strcpy(strchr(ext, '\0'),REDEL_EXT);
1 by brian
clean slate
64
    if (my_rename(org_name, fn_format(name_buff, org_name, "", ext, 2),
65
		  MyFlags))
66
      goto end;
67
  }
68
  else if (my_delete_allow_opened(org_name, MyFlags))
69
      goto end;
70
  if (my_rename(tmp_name,org_name,MyFlags))
71
    goto end;
72
73
  error=0;
74
end:
51.3.18 by Jay Pipes
Phase 5 - Remove DBUG from mysys
75
  return(error);
1 by brian
clean slate
76
} /* my_redel */
77
78
79
	/* Copy stat from one file to another */
80
	/* Return -1 if can't get stat, 1 if wrong type of file */
81
82
int my_copystat(const char *from, const char *to, int MyFlags)
83
{
84
  struct stat statbuf;
85
86
  if (stat((char*) from, &statbuf))
87
  {
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
88
    errno=errno;
1 by brian
clean slate
89
    if (MyFlags & (MY_FAE+MY_WME))
90
      my_error(EE_STAT, MYF(ME_BELL+ME_WAITTANG),from,errno);
91
    return -1;				/* Can't get stat on input file */
92
  }
93
  if ((statbuf.st_mode & S_IFMT) != S_IFREG)
94
    return 1;
398.1.10 by Monty Taylor
Actually removed VOID() this time.
95
  chmod(to, statbuf.st_mode & 07777);		/* Copy modes */
1 by brian
clean slate
96
97
  if (statbuf.st_nlink > 1 && MyFlags & MY_LINK_WARNING)
98
  {
99
    if (MyFlags & MY_LINK_WARNING)
100
      my_error(EE_LINK_WARNING,MYF(ME_BELL+ME_WAITTANG),from,statbuf.st_nlink);
101
  }
512.1.1 by Stewart Smith
a few warnings that show up on ubuntu 8.10: unchecked return codes, not fromat string
102
  if(chown(to, statbuf.st_uid, statbuf.st_gid)!=0)
103
    return 1;
1 by brian
clean slate
104
105
#ifndef __ZTC__
106
  if (MyFlags & MY_COPYTIME)
107
  {
108
    struct utimbuf timep;
109
    timep.actime  = statbuf.st_atime;
110
    timep.modtime = statbuf.st_mtime;
398.1.10 by Monty Taylor
Actually removed VOID() this time.
111
    utime((char*) to, &timep);/* Update last accessed and modified times */
1 by brian
clean slate
112
  }
113
#else
114
  if (MyFlags & MY_COPYTIME)
115
  {
116
    time_t time[2];
117
    time[0]= statbuf.st_atime;
118
    time[1]= statbuf.st_mtime;
398.1.10 by Monty Taylor
Actually removed VOID() this time.
119
    utime((char*) to, time);/* Update last accessed and modified times */
1 by brian
clean slate
120
  }
121
#endif
122
  return 0;
123
} /* my_copystat */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
124
125
} /* namespace internal */
126
} /* namespace drizzled */