1
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
3
This library is free software; you can redistribute it and/or
4
modify it under the terms of the GNU Library General Public
5
License as published by the Free Software Foundation; either
6
version 2 of the License, or (at your option) any later version.
8
This library is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
Library General Public License for more details.
13
You should have received a copy of the GNU Library General Public
14
License along with this library; if not, write to the Free
15
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18
#define USES_TYPES /* sys/types is included */
19
#include "mysys_priv.h"
21
#include "mysys_err.h"
22
#if defined(HAVE_SYS_UTIME_H)
23
#include <sys/utime.h>
24
#elif defined(HAVE_UTIME_H)
33
/* Rename with copy stat form old file */
34
/* Copy stats from old file to new file, deletes orginal and */
35
/* changes new file name to old file name */
37
int my_redel(const char *org_name, const char *tmp_name, myf MyFlags)
39
DBUG_ENTER("my_redel");
40
DBUG_PRINT("my",("org_name: '%s' tmp_name: '%s' MyFlags: %d",
41
org_name,tmp_name,MyFlags));
43
if (my_copystat(org_name,tmp_name,MyFlags) < 0 ||
44
my_delete(org_name,MyFlags) ||
45
my_rename(tmp_name,org_name,MyFlags))
51
/* Copy stat from one file to another */
52
/* Return -1 if can't get stat, 1 if wrong type of file */
54
int my_copystat(const char *from, const char *to, int MyFlags)
58
if (stat((char*) from, &statbuf))
61
if (MyFlags & (MY_FAE+MY_WME))
62
my_error(EE_STAT, MYF(ME_BELL+ME_WAITTANG),from,errno);
63
return -1; /* Can't get stat on input file */
65
if ((statbuf.st_mode & S_IFMT) != S_IFREG)
67
VOID(chmod(to, statbuf.st_mode & 07777)); /* Copy modes */
69
#if !defined(MSDOS) && !defined(__WIN__) && !defined(__EMX__)
70
if (statbuf.st_nlink > 1 && MyFlags & MY_LINK_WARNING)
72
if (MyFlags & MY_LINK_WARNING)
73
my_error(EE_LINK_WARNING,MYF(ME_BELL+ME_WAITTANG),from,statbuf.st_nlink);
75
VOID(chown(to, statbuf.st_uid, statbuf.st_gid)); /* Copy ownership */
80
if (MyFlags & MY_COPYTIME)
83
timep.actime = statbuf.st_atime;
84
timep.modtime = statbuf.st_mtime;
85
VOID(utime((char*) to, &timep));/* Update last accessed and modified times */
88
if (MyFlags & MY_COPYTIME)
91
time[0]= statbuf.st_atime;
92
time[1]= statbuf.st_mtime;
93
VOID(utime((char*) to, time));/* Update last accessed and modified times */