~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_copy.c

  • Committer: Brian Aker
  • Date: 2008-07-14 22:40:46 UTC
  • Revision ID: brian@tangent.org-20080714224046-x183907w9wp1txwv
Removed sql_manager. Ever heard of just setting up the OS to sync when you
want it to?

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
#include "mysys_priv.h"
17
17
#include <my_dir.h> /* for stat */
18
 
#include <mystrings/m_string.h>
 
18
#include <m_string.h>
19
19
#if defined(HAVE_UTIME_H)
20
20
#include <utime.h>
21
21
#elif defined(HAVE_SYS_UTIME_H)
28
28
};
29
29
#endif
30
30
 
31
 
#include <drizzled/util/test.h>
32
31
 
33
32
/*
34
33
  int my_copy(const char *from, const char *to, myf MyFlags)
51
50
 
52
51
int my_copy(const char *from, const char *to, myf MyFlags)
53
52
{
54
 
  uint32_t Count;
 
53
  uint Count;
55
54
  bool new_file_stat= 0; /* 1 if we could stat "to" */
56
55
  int create_flag;
57
56
  File from_file,to_file;
58
 
  unsigned char buff[IO_SIZE];
 
57
  uchar buff[IO_SIZE];
59
58
  struct stat stat_buff,new_stat_buff;
 
59
  DBUG_ENTER("my_copy");
 
60
  DBUG_PRINT("my",("from %s to %s MyFlags %d", from, to, MyFlags));
60
61
 
61
62
  from_file=to_file= -1;
62
 
  assert(!(MyFlags & (MY_FNABP | MY_NABP))); /* for my_read/my_write */
 
63
  DBUG_ASSERT(!(MyFlags & (MY_FNABP | MY_NABP))); /* for my_read/my_write */
63
64
  if (MyFlags & MY_HOLD_ORIGINAL_MODES)         /* Copy stat if possible */
64
65
    new_file_stat= test(!stat((char*) to, &new_stat_buff));
65
66
 
66
 
  if ((from_file=my_open(from,O_RDONLY,MyFlags)) >= 0)
 
67
  if ((from_file=my_open(from,O_RDONLY | O_SHARE,MyFlags)) >= 0)
67
68
  {
68
69
    if (stat(from, &stat_buff))
69
70
    {
75
76
    create_flag= (MyFlags & MY_DONT_OVERWRITE_FILE) ? O_EXCL : O_TRUNC;
76
77
 
77
78
    if ((to_file=  my_create(to,(int) stat_buff.st_mode,
78
 
                             O_WRONLY | create_flag,
 
79
                             O_WRONLY | create_flag | O_BINARY | O_SHARE,
79
80
                             MyFlags)) < 0)
80
81
      goto err;
81
82
 
87
88
    }
88
89
 
89
90
    if (my_close(from_file,MyFlags) | my_close(to_file,MyFlags))
90
 
      return(-1);                               /* Error on close */
 
91
      DBUG_RETURN(-1);                          /* Error on close */
91
92
 
92
93
    /* Copy modes if possible */
93
94
 
94
95
    if (MyFlags & MY_HOLD_ORIGINAL_MODES && !new_file_stat)
95
 
        return(0);                      /* File copyed but not stat */
96
 
    chmod(to, stat_buff.st_mode & 07777); /* Copy modes */
97
 
    chown(to, stat_buff.st_uid,stat_buff.st_gid); /* Copy ownership */
 
96
        DBUG_RETURN(0);                 /* File copyed but not stat */
 
97
    VOID(chmod(to, stat_buff.st_mode & 07777)); /* Copy modes */
 
98
    VOID(chown(to, stat_buff.st_uid,stat_buff.st_gid)); /* Copy ownership */
98
99
    if (MyFlags & MY_COPYTIME)
99
100
    {
100
101
      struct utimbuf timep;
101
102
      timep.actime  = stat_buff.st_atime;
102
103
      timep.modtime = stat_buff.st_mtime;
103
 
      utime((char*) to, &timep); /* last accessed and modified times */
 
104
      VOID(utime((char*) to, &timep)); /* last accessed and modified times */
104
105
    }
105
 
    return(0);
 
106
    DBUG_RETURN(0);
106
107
  }
107
108
 
108
109
err:
109
 
  if (from_file >= 0) my_close(from_file,MyFlags);
 
110
  if (from_file >= 0) VOID(my_close(from_file,MyFlags));
110
111
  if (to_file >= 0)
111
112
  {
112
 
    my_close(to_file, MyFlags);
 
113
    VOID(my_close(to_file, MyFlags));
113
114
    /* attempt to delete the to-file we've partially written */
114
 
    my_delete(to, MyFlags);
 
115
    VOID(my_delete(to, MyFlags));
115
116
  }
116
 
  return(-1);
 
117
  DBUG_RETURN(-1);
117
118
} /* my_copy */