~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_copy.cc

Moved the last of the libdrizzleclient calls into Protocol.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
#include "mysys_priv.h"
17
 
#include <my_dir.h> /* for stat */
 
17
 
18
18
#include <mystrings/m_string.h>
19
19
#if defined(HAVE_UTIME_H)
20
20
#include <utime.h>
28
28
};
29
29
#endif
30
30
 
 
31
#include <drizzled/util/test.h>
31
32
 
32
33
/*
33
34
  int my_copy(const char *from, const char *to, myf MyFlags)
50
51
 
51
52
int my_copy(const char *from, const char *to, myf MyFlags)
52
53
{
53
 
  uint Count;
 
54
  uint32_t Count;
54
55
  bool new_file_stat= 0; /* 1 if we could stat "to" */
55
56
  int create_flag;
56
57
  File from_file,to_file;
57
 
  uchar buff[IO_SIZE];
 
58
  unsigned char buff[IO_SIZE];
58
59
  struct stat stat_buff,new_stat_buff;
59
60
 
60
61
  from_file=to_file= -1;
62
63
  if (MyFlags & MY_HOLD_ORIGINAL_MODES)         /* Copy stat if possible */
63
64
    new_file_stat= test(!stat((char*) to, &new_stat_buff));
64
65
 
65
 
  if ((from_file=my_open(from,O_RDONLY | O_SHARE,MyFlags)) >= 0)
 
66
  if ((from_file=my_open(from,O_RDONLY,MyFlags)) >= 0)
66
67
  {
67
68
    if (stat(from, &stat_buff))
68
69
    {
74
75
    create_flag= (MyFlags & MY_DONT_OVERWRITE_FILE) ? O_EXCL : O_TRUNC;
75
76
 
76
77
    if ((to_file=  my_create(to,(int) stat_buff.st_mode,
77
 
                             O_WRONLY | create_flag | O_BINARY | O_SHARE,
 
78
                             O_WRONLY | create_flag,
78
79
                             MyFlags)) < 0)
79
80
      goto err;
80
81
 
81
82
    while ((Count=my_read(from_file, buff, sizeof(buff), MyFlags)) != 0)
82
83
    {
83
 
        if (Count == (uint) -1 ||
 
84
        if (Count == (uint32_t) -1 ||
84
85
            my_write(to_file,buff,Count,MYF(MyFlags | MY_NABP)))
85
86
        goto err;
86
87
    }
92
93
 
93
94
    if (MyFlags & MY_HOLD_ORIGINAL_MODES && !new_file_stat)
94
95
        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 */
 
96
    chmod(to, stat_buff.st_mode & 07777); /* Copy modes */
 
97
    if(chown(to, stat_buff.st_uid,stat_buff.st_gid)!=0)
 
98
        return 0;
97
99
    if (MyFlags & MY_COPYTIME)
98
100
    {
99
101
      struct utimbuf timep;
100
102
      timep.actime  = stat_buff.st_atime;
101
103
      timep.modtime = stat_buff.st_mtime;
102
 
      VOID(utime((char*) to, &timep)); /* last accessed and modified times */
 
104
      utime((char*) to, &timep); /* last accessed and modified times */
103
105
    }
104
106
    return(0);
105
107
  }
106
108
 
107
109
err:
108
 
  if (from_file >= 0) VOID(my_close(from_file,MyFlags));
 
110
  if (from_file >= 0) my_close(from_file,MyFlags);
109
111
  if (to_file >= 0)
110
112
  {
111
 
    VOID(my_close(to_file, MyFlags));
 
113
    my_close(to_file, MyFlags);
112
114
    /* attempt to delete the to-file we've partially written */
113
 
    VOID(my_delete(to, MyFlags));
 
115
    my_delete(to, MyFlags);
114
116
  }
115
117
  return(-1);
116
118
} /* my_copy */