~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_copy.c

Merged vcol stuff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
 
 
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"
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#include "mysys_priv.h"
 
17
#include <my_dir.h> /* for stat */
 
18
#include <mystrings/m_string.h>
23
19
#if defined(HAVE_UTIME_H)
24
20
#include <utime.h>
25
21
#elif defined(HAVE_SYS_UTIME_H)
32
28
};
33
29
#endif
34
30
 
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
 
{
45
31
 
46
32
/*
47
33
  int my_copy(const char *from, const char *to, myf MyFlags)
67
53
  uint32_t Count;
68
54
  bool new_file_stat= 0; /* 1 if we could stat "to" */
69
55
  int create_flag;
70
 
  int from_file,to_file;
 
56
  File from_file,to_file;
71
57
  unsigned char buff[IO_SIZE];
72
58
  struct stat stat_buff,new_stat_buff;
73
59
 
76
62
  if (MyFlags & MY_HOLD_ORIGINAL_MODES)         /* Copy stat if possible */
77
63
    new_file_stat= test(!stat((char*) to, &new_stat_buff));
78
64
 
79
 
  if ((from_file=my_open(from,O_RDONLY,MyFlags)) >= 0)
 
65
  if ((from_file=my_open(from,O_RDONLY | O_SHARE,MyFlags)) >= 0)
80
66
  {
81
67
    if (stat(from, &stat_buff))
82
68
    {
83
 
      errno=errno;
 
69
      my_errno=errno;
84
70
      goto err;
85
71
    }
86
72
    if (MyFlags & MY_HOLD_ORIGINAL_MODES && new_file_stat)
88
74
    create_flag= (MyFlags & MY_DONT_OVERWRITE_FILE) ? O_EXCL : O_TRUNC;
89
75
 
90
76
    if ((to_file=  my_create(to,(int) stat_buff.st_mode,
91
 
                             O_WRONLY | create_flag,
 
77
                             O_WRONLY | create_flag | O_BINARY | O_SHARE,
92
78
                             MyFlags)) < 0)
93
79
      goto err;
94
80
 
95
 
    while ((Count= static_cast<uint32_t>(my_read(from_file, buff,
96
 
            sizeof(buff), MyFlags))) != 0)
 
81
    while ((Count=my_read(from_file, buff, sizeof(buff), MyFlags)) != 0)
97
82
    {
98
 
        if (Count == (uint32_t) -1 ||
 
83
        if (Count == (uint) -1 ||
99
84
            my_write(to_file,buff,Count,MYF(MyFlags | MY_NABP)))
100
85
        goto err;
101
86
    }
108
93
    if (MyFlags & MY_HOLD_ORIGINAL_MODES && !new_file_stat)
109
94
        return(0);                      /* File copyed but not stat */
110
95
    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;
 
96
    chown(to, stat_buff.st_uid,stat_buff.st_gid); /* Copy ownership */
113
97
    if (MyFlags & MY_COPYTIME)
114
98
    {
115
99
      struct utimbuf timep;
130
114
  }
131
115
  return(-1);
132
116
} /* my_copy */
133
 
 
134
 
} /* namespace internal */
135
 
} /* namespace drizzled */