~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/mf_cache.cc

  • Committer: Monty Taylor
  • Date: 2008-11-16 05:36:13 UTC
  • mto: (584.1.9 devel)
  • mto: This revision was merged to the branch mainline in revision 589.
  • Revision ID: monty@inaugust.com-20081116053613-bld4rqxhlkb49c02
Split out cache_row and type_holder.

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 */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
/* Open a temporary file and cache it with io_cache. Delete it on close */
17
17
 
18
 
#include "config.h"
19
 
 
20
 
#include "drizzled/internal/my_sys.h"
21
 
#include "drizzled/internal/m_string.h"
22
 
#include "drizzled/internal/my_static.h"
23
 
#include "drizzled/internal/iocache.h"
24
 
#include "drizzled/error.h"
25
 
 
26
 
namespace drizzled
27
 
{
28
 
namespace internal
29
 
{
30
 
 
31
 
/*
32
 
** Open tempfile cached by st_io_cache
33
 
** Should be used when no seeks are done (only reinit_io_buff)
34
 
** Return false if cache is inited ok
35
 
** The actual file is created when the st_io_cache buffer gets filled
36
 
** If dir is not given, use TMPDIR.
37
 
*/
38
 
 
39
 
bool st_io_cache::open_cached_file(const char *dir_arg, const char *prefix_arg,
40
 
                      size_t cache_size_arg, myf cache_myflags)
41
 
{
42
 
  dir=   dir_arg ? strdup(dir_arg) : (char*) 0;
43
 
  prefix= (prefix_arg ? strdup(prefix_arg) : (char*) 0);
44
 
 
45
 
  if ((dir == NULL) || (prefix == NULL))
46
 
    return true;
47
 
 
48
 
  file_name= 0;
49
 
  buffer= 0;                            /* Mark that not open */
50
 
  if (not init_io_cache(-1, cache_size_arg,WRITE_CACHE,0L,0, MYF(cache_myflags | MY_NABP)))
 
18
#include "mysys_priv.h"
 
19
#include <mystrings/m_string.h>
 
20
#include <mysys/my_static.h>
 
21
#include <mysys/mysys_err.h>
 
22
#include <mysys/iocache.h>
 
23
 
 
24
 
 
25
        /*
 
26
        ** Open tempfile cached by IO_CACHE
 
27
        ** Should be used when no seeks are done (only reinit_io_buff)
 
28
        ** Return 0 if cache is inited ok
 
29
        ** The actual file is created when the IO_CACHE buffer gets filled
 
30
        ** If dir is not given, use TMPDIR.
 
31
        */
 
32
 
 
33
bool open_cached_file(IO_CACHE *cache, const char* dir, const char *prefix,
 
34
                         size_t cache_size, myf cache_myflags)
 
35
{
 
36
  cache->dir=    dir ? my_strdup(dir,MYF(cache_myflags & MY_WME)) : (char*) 0;
 
37
  cache->prefix= (prefix ? my_strdup(prefix,MYF(cache_myflags & MY_WME)) :
 
38
                 (char*) 0);
 
39
  cache->file_name=0;
 
40
  cache->buffer=0;                              /* Mark that not open */
 
41
  if (!init_io_cache(cache,-1,cache_size,WRITE_CACHE,0L,0,
 
42
                     MYF(cache_myflags | MY_NABP)))
51
43
  {
52
 
    return false;
 
44
    return(0);
53
45
  }
54
 
  free(dir);
55
 
  free(prefix);
56
 
 
57
 
  return true;
 
46
  free(cache->dir);
 
47
  free(cache->prefix);
 
48
  return(1);
58
49
}
59
50
 
60
 
/* Create the temporary file */
 
51
        /* Create the temporary file */
61
52
 
62
 
bool st_io_cache::real_open_cached_file()
 
53
bool real_open_cached_file(IO_CACHE *cache)
63
54
{
64
55
  char name_buff[FN_REFLEN];
65
 
 
66
 
  if ((file= create_temp_file(name_buff, dir, prefix, MYF(MY_WME))) >= 0)
 
56
  int error=1;
 
57
  if ((cache->file=create_temp_file(name_buff, cache->dir, cache->prefix,
 
58
                                    (O_RDWR | O_TRUNC),
 
59
                                    MYF(MY_WME))) >= 0)
67
60
  {
 
61
    error=0;
68
62
    my_delete(name_buff,MYF(MY_WME | ME_NOINPUT));
69
 
    return false;
70
63
  }
71
 
 
72
 
  return true;
 
64
  return(error);
73
65
}
74
66
 
75
67
 
76
 
void st_io_cache::close_cached_file()
 
68
void close_cached_file(IO_CACHE *cache)
77
69
{
78
 
  if (my_b_inited(this))
 
70
  if (my_b_inited(cache))
79
71
  {
80
 
    int _file= file;
81
 
    file= -1;                           /* Don't flush data */
82
 
    (void) end_io_cache();
83
 
    if (_file >= 0)
 
72
    File file=cache->file;
 
73
    cache->file= -1;                            /* Don't flush data */
 
74
    (void) end_io_cache(cache);
 
75
    if (file >= 0)
84
76
    {
85
 
      (void) my_close(_file, MYF(0));
 
77
      (void) my_close(file,MYF(0));
86
78
#ifdef CANT_DELETE_OPEN_FILES
87
 
      if (file_name)
 
79
      if (cache->file_name)
88
80
      {
89
 
        (void) my_delete(file_name, MYF(MY_WME | ME_NOINPUT));
90
 
        free(file_name);
 
81
        (void) my_delete(cache->file_name,MYF(MY_WME | ME_NOINPUT));
 
82
        free(cache->file_name);
91
83
      }
92
84
#endif
93
85
    }
94
 
    free(dir);
95
 
    free(prefix);
 
86
    free(cache->dir);
 
87
    free(cache->prefix);
96
88
  }
 
89
  return;
97
90
}
98
 
 
99
 
} /* namespace internal */
100
 
} /* namespace drizzled */