~ubuntu-branches/ubuntu/saucy/drizzle/saucy-proposed

« back to all changes in this revision

Viewing changes to drizzled/internal/my_symlink2.cc

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include <drizzled/error.h>
27
27
#include <drizzled/internal/m_string.h>
28
28
 
29
 
namespace drizzled
30
 
{
31
 
namespace internal
32
 
{
 
29
namespace drizzled {
 
30
namespace internal {
33
31
 
34
32
int my_create_with_symlink(const char *linkname, const char *filename,
35
33
                           int createflags, int access_flags, myf MyFlags)
36
34
{
37
 
  int file;
38
 
  int tmp_errno;
39
35
  /* Test if we should create a link */
40
 
  int create_link;
41
 
  char abs_linkname[FN_REFLEN];
 
36
  bool create_link= false;
42
37
  char rp_buff[PATH_MAX];
43
38
 
44
39
  if (my_disable_symlinks)
45
40
  {
46
41
    /* Create only the file, not the link and file */
47
 
    create_link= 0;
48
42
    if (linkname)
49
43
      filename= linkname;
50
44
  }
51
 
  else
 
45
  else if (linkname)
52
46
  {
53
 
    if (linkname)
54
 
    {
55
 
      if (!realpath(linkname,rp_buff))
56
 
        my_load_path(rp_buff, linkname, NULL);
57
 
      rp_buff[FN_REFLEN-1]= '\0';
58
 
      strcpy(abs_linkname,rp_buff);
59
 
    }
60
 
    create_link= (linkname && strcmp(abs_linkname,filename));
 
47
    if (!realpath(linkname,rp_buff))
 
48
      my_load_path(rp_buff, linkname, NULL);
 
49
    rp_buff[FN_REFLEN-1]= '\0';
 
50
    char abs_linkname[FN_REFLEN];
 
51
    strcpy(abs_linkname, rp_buff);
 
52
    create_link= strcmp(abs_linkname, filename);
61
53
  }
62
54
 
63
55
  if (!(MyFlags & MY_DELETE_OLD))
76
68
    }
77
69
  }
78
70
 
79
 
  if ((file=my_create(filename, createflags, access_flags, MyFlags)) >= 0)
 
71
  int file= my_create(filename, createflags, access_flags, MyFlags);
 
72
  if (file >= 0 && create_link)
80
73
  {
81
 
    if (create_link)
 
74
    /* Delete old link/file */
 
75
    if (MyFlags & MY_DELETE_OLD)
 
76
      my_delete(linkname, MYF(0));
 
77
    /* Create link */
 
78
    if (symlink(filename,linkname))
82
79
    {
83
 
      /* Delete old link/file */
84
 
      if (MyFlags & MY_DELETE_OLD)
85
 
        my_delete(linkname, MYF(0));
86
 
      /* Create link */
87
 
      if (symlink(filename,linkname))
88
 
      {
89
 
        /* Fail, remove everything we have done */
90
 
        tmp_errno=errno;
91
 
        my_close(file,MYF(0));
92
 
        my_delete(filename, MYF(0));
93
 
        file= -1;
94
 
        errno=tmp_errno;
95
 
      }
96
 
      else if (MyFlags & MY_SYNC_DIR)
97
 
        my_sync_dir_by_file(linkname, MyFlags);
 
80
      /* Fail, remove everything we have done */
 
81
      int tmp_errno= errno;
 
82
      my_close(file, MYF(0));
 
83
      my_delete(filename, MYF(0));
 
84
      file= -1;
 
85
      errno= tmp_errno;
98
86
    }
 
87
    else if (MyFlags & MY_SYNC_DIR)
 
88
      my_sync_dir_by_file(linkname, MyFlags);
99
89
  }
100
 
  return(file);
 
90
  return file;
101
91
}
102
92
 
103
93
/*
157
147
    errno= EEXIST;
158
148
    if (MyFlags & MY_WME)
159
149
      my_error(EE_CANTCREATEFILE, MYF(0), tmp_name, EEXIST);
160
 
    return(1);
 
150
    return 1;
161
151
  }
162
152
 
163
153
  /* Create new symlink */
164
154
  if (symlink(tmp_name, to))
165
 
    return(1);
 
155
    return 1;
166
156
  else if (MyFlags & MY_SYNC_DIR)
167
157
    my_sync_dir_by_file(to, MyFlags);
168
158
 
177
167
    int save_errno=errno;
178
168
    my_delete(to, MyFlags);                     /* Remove created symlink */
179
169
    errno=save_errno;
180
 
    return(1);
 
170
    return 1;
181
171
  }
182
172
 
183
173
  /* Remove original symlink */