~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/internal/my_copy.cc

  • Committer: Brian Aker
  • Date: 2010-02-07 01:33:54 UTC
  • Revision ID: brian@gaz-20100207013354-d2pg1n68u5c09pgo
Remove giant include header to its own file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
 
#include "mysys_priv.h"
17
 
#include <my_dir.h> /* for stat */
18
 
#include <mystrings/m_string.h>
 
16
#include "config.h"
 
17
 
 
18
#include "drizzled/internal/my_sys.h"
 
19
 
 
20
#include <fcntl.h>
 
21
 
 
22
#include "drizzled/internal/m_string.h"
19
23
#if defined(HAVE_UTIME_H)
20
24
#include <utime.h>
21
25
#elif defined(HAVE_SYS_UTIME_H)
28
32
};
29
33
#endif
30
34
 
 
35
#ifdef HAVE_SYS_STAT_H
 
36
# include <sys/stat.h>
 
37
#endif
 
38
 
 
39
#include <drizzled/util/test.h>
 
40
 
 
41
namespace drizzled
 
42
{
 
43
namespace internal
 
44
{
31
45
 
32
46
/*
33
47
  int my_copy(const char *from, const char *to, myf MyFlags)
50
64
 
51
65
int my_copy(const char *from, const char *to, myf MyFlags)
52
66
{
53
 
  uint Count;
 
67
  uint32_t Count;
54
68
  bool new_file_stat= 0; /* 1 if we could stat "to" */
55
69
  int create_flag;
56
 
  File from_file,to_file;
57
 
  uchar buff[IO_SIZE];
 
70
  int from_file,to_file;
 
71
  unsigned char buff[IO_SIZE];
58
72
  struct stat stat_buff,new_stat_buff;
59
73
 
60
74
  from_file=to_file= -1;
62
76
  if (MyFlags & MY_HOLD_ORIGINAL_MODES)         /* Copy stat if possible */
63
77
    new_file_stat= test(!stat((char*) to, &new_stat_buff));
64
78
 
65
 
  if ((from_file=my_open(from,O_RDONLY | O_SHARE,MyFlags)) >= 0)
 
79
  if ((from_file=my_open(from,O_RDONLY,MyFlags)) >= 0)
66
80
  {
67
81
    if (stat(from, &stat_buff))
68
82
    {
69
 
      my_errno=errno;
 
83
      errno=errno;
70
84
      goto err;
71
85
    }
72
86
    if (MyFlags & MY_HOLD_ORIGINAL_MODES && new_file_stat)
74
88
    create_flag= (MyFlags & MY_DONT_OVERWRITE_FILE) ? O_EXCL : O_TRUNC;
75
89
 
76
90
    if ((to_file=  my_create(to,(int) stat_buff.st_mode,
77
 
                             O_WRONLY | create_flag | O_BINARY | O_SHARE,
 
91
                             O_WRONLY | create_flag,
78
92
                             MyFlags)) < 0)
79
93
      goto err;
80
94
 
81
 
    while ((Count=my_read(from_file, buff, sizeof(buff), MyFlags)) != 0)
 
95
    while ((Count= static_cast<uint32_t>(my_read(from_file, buff,
 
96
            sizeof(buff), MyFlags))) != 0)
82
97
    {
83
 
        if (Count == (uint) -1 ||
 
98
        if (Count == (uint32_t) -1 ||
84
99
            my_write(to_file,buff,Count,MYF(MyFlags | MY_NABP)))
85
100
        goto err;
86
101
    }
92
107
 
93
108
    if (MyFlags & MY_HOLD_ORIGINAL_MODES && !new_file_stat)
94
109
        return(0);                      /* File copyed but not stat */
95
 
    VOID(chmod(to, stat_buff.st_mode & 07777)); /* Copy modes */
96
 
    VOID(chown(to, stat_buff.st_uid,stat_buff.st_gid)); /* Copy ownership */
 
110
    chmod(to, stat_buff.st_mode & 07777); /* Copy modes */
 
111
    if(chown(to, stat_buff.st_uid,stat_buff.st_gid)!=0)
 
112
        return 0;
97
113
    if (MyFlags & MY_COPYTIME)
98
114
    {
99
115
      struct utimbuf timep;
100
116
      timep.actime  = stat_buff.st_atime;
101
117
      timep.modtime = stat_buff.st_mtime;
102
 
      VOID(utime((char*) to, &timep)); /* last accessed and modified times */
 
118
      utime((char*) to, &timep); /* last accessed and modified times */
103
119
    }
104
120
    return(0);
105
121
  }
106
122
 
107
123
err:
108
 
  if (from_file >= 0) VOID(my_close(from_file,MyFlags));
 
124
  if (from_file >= 0) my_close(from_file,MyFlags);
109
125
  if (to_file >= 0)
110
126
  {
111
 
    VOID(my_close(to_file, MyFlags));
 
127
    my_close(to_file, MyFlags);
112
128
    /* attempt to delete the to-file we've partially written */
113
 
    VOID(my_delete(to, MyFlags));
 
129
    my_delete(to, MyFlags);
114
130
  }
115
131
  return(-1);
116
132
} /* my_copy */
 
133
 
 
134
} /* namespace internal */
 
135
} /* namespace drizzled */