~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_symlink2.cc

  • Committer: Monty Taylor
  • Date: 2009-12-23 08:01:21 UTC
  • mto: This revision was merged to the branch mainline in revision 1253.
  • Revision ID: mordred@inaugust.com-20091223080121-iveugdrewkp7iqyi
Oy. Bigger change than I normally like - but this stuff is all intertwined.
Moved a bunch of things to public drizzled/ area. Split some files. Made some
convenience libs. EVENTUALLY, some of this will be able to be re-factored, but
for now I'm ok with erring on the side of too many files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
*/
22
22
 
23
23
#include "mysys/mysys_priv.h"
24
 
#include "mysys/mysys_err.h"
 
24
#include "drizzled/my_error.h"
25
25
#include <mystrings/m_string.h>
26
26
 
27
27
int my_create_with_symlink(const char *linkname, const char *filename,
57
57
  {
58
58
    if (!access(filename,F_OK))
59
59
    {
60
 
      my_errno= errno= EEXIST;
 
60
      errno= errno= EEXIST;
61
61
      my_error(EE_CANTCREATEFILE, MYF(0), filename, EEXIST);
62
62
      return(-1);
63
63
    }
64
64
    if (create_link && !access(linkname,F_OK))
65
65
    {
66
 
      my_errno= errno= EEXIST;
 
66
      errno= errno= EEXIST;
67
67
      my_error(EE_CANTCREATEFILE, MYF(0), linkname, EEXIST);
68
68
      return(-1);
69
69
    }
80
80
      if (symlink(filename,linkname))
81
81
      {
82
82
        /* Fail, remove everything we have done */
83
 
        tmp_errno=my_errno;
 
83
        tmp_errno=errno;
84
84
        my_close(file,MYF(0));
85
85
        my_delete(filename, MYF(0));
86
86
        file= -1;
87
 
        my_errno=tmp_errno;
 
87
        errno=tmp_errno;
88
88
      }
89
89
      else if (MyFlags & MY_SYNC_DIR)
90
90
        my_sync_dir_by_file(linkname, MyFlags);
147
147
  name_is_different= strcmp(link_name, tmp_name);
148
148
  if (name_is_different && !access(tmp_name, F_OK))
149
149
  {
150
 
    my_errno= EEXIST;
 
150
    errno= EEXIST;
151
151
    if (MyFlags & MY_WME)
152
152
      my_error(EE_CANTCREATEFILE, MYF(0), tmp_name, EEXIST);
153
153
    return(1);
167
167
 
168
168
  if (name_is_different && my_rename(link_name, tmp_name, MyFlags))
169
169
  {
170
 
    int save_errno=my_errno;
 
170
    int save_errno=errno;
171
171
    my_delete(to, MyFlags);                     /* Remove created symlink */
172
 
    my_errno=save_errno;
 
172
    errno=save_errno;
173
173
    return(1);
174
174
  }
175
175
 
176
176
  /* Remove original symlink */
177
177
  if (my_delete(from, MyFlags))
178
178
  {
179
 
    int save_errno=my_errno;
 
179
    int save_errno=errno;
180
180
    /* Remove created link */
181
181
    my_delete(to, MyFlags);
182
182
    /* Rename file back */
183
183
    if (strcmp(link_name, tmp_name))
184
184
      (void) my_rename(tmp_name, link_name, MyFlags);
185
 
    my_errno=save_errno;
 
185
    errno=save_errno;
186
186
    result= 1;
187
187
  }
188
188
  return(result);