~mysql/mysql-server/mysql-6.0

« back to all changes in this revision

Viewing changes to mysys/my_redel.c

  • Committer: bk at mysql
  • Date: 2000-07-31 19:29:14 UTC
  • Revision ID: sp1r-bk@work.mysql.com-20000731192914-08846
Import changeset

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
 
2
   
 
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.
 
7
   
 
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.
 
12
   
 
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,
 
16
   MA 02111-1307, USA */
 
17
 
 
18
#define USES_TYPES                              /* sys/types is included */
 
19
#include "mysys_priv.h"
 
20
#include <my_dir.h>
 
21
#include "mysys_err.h"
 
22
#if defined(HAVE_SYS_UTIME_H)
 
23
#include <sys/utime.h>
 
24
#elif defined(HAVE_UTIME_H)
 
25
#include <utime.h>
 
26
#elif !defined(HPUX)
 
27
struct utimbuf {
 
28
  time_t actime;
 
29
  time_t modtime;
 
30
};
 
31
#endif
 
32
 
 
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 */
 
36
 
 
37
int my_redel(const char *org_name, const char *tmp_name, myf MyFlags)
 
38
{
 
39
  DBUG_ENTER("my_redel");
 
40
  DBUG_PRINT("my",("org_name: '%s' tmp_name: '%s'  MyFlags: %d",
 
41
                   org_name,tmp_name,MyFlags));
 
42
 
 
43
  if (my_copystat(org_name,tmp_name,MyFlags) < 0 ||
 
44
      my_delete(org_name,MyFlags) ||
 
45
      my_rename(tmp_name,org_name,MyFlags))
 
46
    DBUG_RETURN(1);
 
47
  DBUG_RETURN(0);
 
48
} /* my_redel */
 
49
 
 
50
 
 
51
        /* Copy stat from one file to another */
 
52
        /* Return -1 if can't get stat, 1 if wrong type of file */
 
53
 
 
54
int my_copystat(const char *from, const char *to, int MyFlags)
 
55
{
 
56
  struct stat statbuf;
 
57
 
 
58
  if (stat((char*) from, &statbuf))
 
59
  {
 
60
    my_errno=errno;
 
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 */
 
64
  }
 
65
  if ((statbuf.st_mode & S_IFMT) != S_IFREG)
 
66
    return 1;
 
67
  VOID(chmod(to, statbuf.st_mode & 07777));             /* Copy modes */
 
68
 
 
69
#if !defined(MSDOS) && !defined(__WIN__) && !defined(__EMX__)
 
70
  if (statbuf.st_nlink > 1 && MyFlags & MY_LINK_WARNING)
 
71
  {
 
72
    if (MyFlags & MY_LINK_WARNING)
 
73
      my_error(EE_LINK_WARNING,MYF(ME_BELL+ME_WAITTANG),from,statbuf.st_nlink);
 
74
  }
 
75
  VOID(chown(to, statbuf.st_uid, statbuf.st_gid));      /* Copy ownership */
 
76
#endif /* MSDOS */
 
77
 
 
78
#ifndef VMS
 
79
#ifndef __ZTC__
 
80
  if (MyFlags & MY_COPYTIME)
 
81
  {
 
82
    struct utimbuf timep;
 
83
    timep.actime  = statbuf.st_atime;
 
84
    timep.modtime = statbuf.st_mtime;
 
85
    VOID(utime((char*) to, &timep));/* Update last accessed and modified times */
 
86
  }
 
87
#else
 
88
  if (MyFlags & MY_COPYTIME)
 
89
  {
 
90
    time_t time[2];
 
91
    time[0]= statbuf.st_atime;
 
92
    time[1]= statbuf.st_mtime;
 
93
    VOID(utime((char*) to, time));/* Update last accessed and modified times */
 
94
  }
 
95
#endif
 
96
#endif
 
97
  return 0;
 
98
} /* my_copystat */