~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_symlink2.c

  • Committer: Brian Aker
  • Date: 2008-07-15 06:45:16 UTC
  • Revision ID: brian@tangent.org-20080715064516-fnbq7kowh7w57bxj
Merge Monty's code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
#include "mysys_priv.h"
24
24
#include "mysys_err.h"
25
 
#include <mystrings/m_string.h>
 
25
#include <m_string.h>
26
26
 
27
27
File my_create_with_symlink(const char *linkname, const char *filename,
28
28
                            int createflags, int access_flags, myf MyFlags)
32
32
  /* Test if we should create a link */
33
33
  int create_link;
34
34
  char abs_linkname[FN_REFLEN];
 
35
  DBUG_ENTER("my_create_with_symlink");
 
36
  DBUG_PRINT("enter", ("linkname: %s  filename: %s",
 
37
                       linkname ? linkname : "(null)",
 
38
                       filename ? filename : "(null)"));
35
39
 
36
40
  if (my_disable_symlinks)
37
41
  {
 
42
    DBUG_PRINT("info", ("Symlinks disabled"));
38
43
    /* Create only the file, not the link and file */
39
44
    create_link= 0;
40
45
    if (linkname)
53
58
    {
54
59
      my_errno= errno= EEXIST;
55
60
      my_error(EE_CANTCREATEFILE, MYF(0), filename, EEXIST);
56
 
      return(-1);
 
61
      DBUG_RETURN(-1);
57
62
    }
58
63
    if (create_link && !access(linkname,F_OK))
59
64
    {
60
65
      my_errno= errno= EEXIST;
61
66
      my_error(EE_CANTCREATEFILE, MYF(0), linkname, EEXIST);
62
 
      return(-1);
 
67
      DBUG_RETURN(-1);
63
68
    }
64
69
  }
65
70
 
82
87
      }
83
88
    }
84
89
  }
85
 
  return(file);
 
90
  DBUG_RETURN(file);
86
91
}
87
92
 
88
93
/*
96
101
  int was_symlink= (!my_disable_symlinks &&
97
102
                    !my_readlink(link_name, name, MYF(0)));
98
103
  int result;
 
104
  DBUG_ENTER("my_delete_with_symlink");
99
105
 
100
106
  if (!(result=my_delete(name, MyFlags)))
101
107
  {
102
108
    if (was_symlink)
103
109
      result=my_delete(link_name, MyFlags);
104
110
  }
105
 
  return(result);
 
111
  DBUG_RETURN(result);
106
112
}
107
113
 
108
114
/*
125
131
                    !my_readlink(link_name, from, MYF(0)));
126
132
  int result=0;
127
133
  int name_is_different;
 
134
  DBUG_ENTER("my_rename_with_symlink");
128
135
 
129
136
  if (!was_symlink)
130
 
    return(my_rename(from, to, MyFlags));
 
137
    DBUG_RETURN(my_rename(from, to, MyFlags));
131
138
 
132
139
  /* Change filename that symlink pointed to */
133
 
  my_stpcpy(tmp_name, to);
 
140
  strmov(tmp_name, to);
134
141
  fn_same(tmp_name,link_name,1);                /* Copy dir */
135
142
  name_is_different= strcmp(link_name, tmp_name);
136
143
  if (name_is_different && !access(tmp_name, F_OK))
138
145
    my_errno= EEXIST;
139
146
    if (MyFlags & MY_WME)
140
147
      my_error(EE_CANTCREATEFILE, MYF(0), tmp_name, EEXIST);
141
 
    return(1);
 
148
    DBUG_RETURN(1);
142
149
  }
143
150
 
144
151
  /* Create new symlink */
145
152
  if (my_symlink(tmp_name, to, MyFlags))
146
 
    return(1);
 
153
    DBUG_RETURN(1);
147
154
 
148
155
  /*
149
156
    Rename symlinked file if the base name didn't change.
156
163
    int save_errno=my_errno;
157
164
    my_delete(to, MyFlags);                     /* Remove created symlink */
158
165
    my_errno=save_errno;
159
 
    return(1);
 
166
    DBUG_RETURN(1);
160
167
  }
161
168
 
162
169
  /* Remove original symlink */
171
178
    my_errno=save_errno;
172
179
    result= 1;
173
180
  }
174
 
  return(result);
 
181
  DBUG_RETURN(result);
175
182
#endif /* HAVE_READLINK */
176
183
}