mirror of
				https://github.com/MariaDB/server.git
				synced 2025-11-03 14:33:32 +03:00 
			
		
		
		
	- Encoding itself, implemented as a charset "filename". Originally planned to use '.' as an escape character, but now changed to '@' for two reasons: "ls" does not return file names starting with '.' considering them as a kind of hidden files; some platforms do not allow several dots in a file name. - replacing many calls of my_snprintf() and strnxmov() to the new build_table_filename(). - Adding MY_APPEND_EXT mysys flag, to append an extention rather that replace it. - Replacing all numeric constants in fn_format flag arguments to their mysys definitions, e.g. MY_UNPACK_FILENAME, - Predictability in several function/methods: when a table name can appear with or withot .frm extension. Some functions/methods were changed so accept names strictly with .frm, other - strictly without .frm extensions. Several DBUG_ASSERTs were added to check whether an extension is passed. Many files: table name to file name encoding mysql_priv.h: Prototypes for new table name encoding tools. ctype-utf8.c: Implementing "filename" charset for table name to file name encoding. row0mysql.c: Fixing table name prefix. mf_format.c: Adding MY_APPEND_EXT processing. Many files: Fixing tests. my_sys.h: Adding new flag to append rather than replace an extension. m_ctype.h: Adding "filename" charset definition. include/m_ctype.h: Adding "filename" charset definition. include/my_sys.h: Adding new flag to append rather than replace an extension. mysql-test/t/alter_table.test: Fixing tests. mysql-test/t/create.test: Fixing tests. mysql-test/t/show_check.test: Fixing tests. mysql-test/r/alter_table.result: Fixing tests. mysql-test/r/create.result: Fixing tests. mysql-test/r/mysqldump.result: Fixing tests. mysys/mf_format.c: Adding MY_APPEND_EXT processing. sql/discover.cc: table name to file name encoding sql/ha_berkeley.cc: table name to file name encoding sql/ha_innodb.cc: table name to file name encoding sql/ha_myisam.cc: table name to file name encoding sql/ha_myisammrg.cc: table name to file name encoding sql/ha_ndbcluster.cc: table name to file name encoding sql/ha_partition.cc: table name to file name encoding sql/handler.cc: table name to file name encoding. sql/init.cc: table name to file name encoding sql/mysqld.cc: table name to file name encoding sql/parse_file.cc: table name to file name encoding sql/sql_acl.cc: table name to file name encoding sql/sql_base.cc: table name to file name encoding sql/sql_db.cc: table name to file name encoding sql/sql_delete.cc: table name to file name encoding sql/sql_rename.cc: table name to file name encoding sql/sql_show.cc: table name to file name encoding sql/sql_table.cc: table name to file name encoding sql/sql_trigger.cc: table name to file name encoding sql/sql_view.cc: table name to file name encoding sql/strfunc.cc: table name to file name encoding sql/table.cc: table name to file name encoding sql/unireg.cc: table name to file name encoding storage/innobase/row/row0mysql.c: Fixing table name prefix. , storage/myisam/mi_create.c: table name to file name encoding storage/myisam/mi_delete_table.c: table name to file name encoding storage/myisam/mi_open.c: table name to file name encoding storage/myisam/mi_rename.c: table name to file name encoding strings/ctype-utf8.c: Implementing "filename" charset for table name to file name encoding. sql/mysql_priv.h: Prototypes for new table name encoding tools. storage/myisammrg/myrg_create.c: table name to file name encoding storage/myisammrg/myrg_open.c: table name to file name encoding
		
			
				
	
	
		
			142 lines
		
	
	
		
			3.9 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			142 lines
		
	
	
		
			3.9 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
/* Copyright (C) 2000 MySQL AB
 | 
						|
 | 
						|
   This program is free software; you can redistribute it and/or modify
 | 
						|
   it under the terms of the GNU General Public License as published by
 | 
						|
   the Free Software Foundation; either version 2 of the License, or
 | 
						|
   (at your option) any later version.
 | 
						|
 | 
						|
   This program is distributed in the hope that it will be useful,
 | 
						|
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
						|
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
						|
   GNU General Public License for more details.
 | 
						|
 | 
						|
   You should have received a copy of the GNU General Public License
 | 
						|
   along with this program; if not, write to the Free Software
 | 
						|
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 | 
						|
 | 
						|
#include "mysys_priv.h"
 | 
						|
#include <m_string.h>
 | 
						|
 | 
						|
/*
 | 
						|
  Formats a filename with possible replace of directory of extension
 | 
						|
  Function can handle the case where 'to' == 'name'
 | 
						|
  For a description of the flag values, consult my_sys.h
 | 
						|
  The arguments should be in unix format.
 | 
						|
*/
 | 
						|
 | 
						|
my_string fn_format(my_string to, const char *name, const char *dir,
 | 
						|
		    const char *extension, uint flag)
 | 
						|
{
 | 
						|
  reg1 uint length;
 | 
						|
  char dev[FN_REFLEN], buff[FN_REFLEN], *pos, *startpos;
 | 
						|
  const char *ext;
 | 
						|
  DBUG_ENTER("fn_format");
 | 
						|
  DBUG_PRINT("enter",("name: %s  dir: %s  extension: %s  flag: %d",
 | 
						|
		       name,dir,extension,flag));
 | 
						|
 | 
						|
  /* Copy and skip directory */
 | 
						|
  name+=(length=dirname_part(dev,(startpos=(my_string) name)));
 | 
						|
  if (length == 0 || (flag & MY_REPLACE_DIR))
 | 
						|
  {
 | 
						|
    /* Use given directory */
 | 
						|
    convert_dirname(dev,dir,NullS);		/* Fix to this OS */
 | 
						|
  }
 | 
						|
  else if ((flag & MY_RELATIVE_PATH) && !test_if_hard_path(dev))
 | 
						|
  {
 | 
						|
    /* Put 'dir' before the given path */
 | 
						|
    strmake(buff,dev,sizeof(buff)-1);
 | 
						|
    pos=convert_dirname(dev,dir,NullS);
 | 
						|
    strmake(pos,buff,sizeof(buff)-1- (int) (pos-dev));
 | 
						|
  }
 | 
						|
 | 
						|
  if (flag & MY_PACK_FILENAME)
 | 
						|
    pack_dirname(dev,dev);			/* Put in ./.. and ~/.. */
 | 
						|
  if (flag & MY_UNPACK_FILENAME)
 | 
						|
    (void) unpack_dirname(dev,dev);		/* Replace ~/.. with dir */
 | 
						|
 | 
						|
  if (!(flag & MY_APPEND_EXT) &&
 | 
						|
      (pos= (char*) strchr(name,FN_EXTCHAR)) != NullS)
 | 
						|
  {
 | 
						|
    if ((flag & MY_REPLACE_EXT) == 0)		/* If we should keep old ext */
 | 
						|
    {
 | 
						|
      length=strlength(name);			/* Use old extension */
 | 
						|
      ext = "";
 | 
						|
    }
 | 
						|
    else
 | 
						|
    {
 | 
						|
      length=(uint) (pos-(char*) name);		/* Change extension */
 | 
						|
      ext= extension;
 | 
						|
    }
 | 
						|
  }
 | 
						|
  else
 | 
						|
  {
 | 
						|
    length=strlength(name);			/* No ext, use the now one */
 | 
						|
    ext=extension;
 | 
						|
  }
 | 
						|
 | 
						|
  if (strlen(dev)+length+strlen(ext) >= FN_REFLEN || length >= FN_LEN )
 | 
						|
  {
 | 
						|
    /* To long path, return original or NULL */
 | 
						|
    uint tmp_length;
 | 
						|
    if (flag & MY_SAFE_PATH)
 | 
						|
      return NullS;
 | 
						|
    tmp_length=strlength(startpos);
 | 
						|
    DBUG_PRINT("error",("dev: '%s'  ext: '%s'  length: %d",dev,ext,length));
 | 
						|
    (void) strmake(to,startpos,min(tmp_length,FN_REFLEN-1));
 | 
						|
  }
 | 
						|
  else
 | 
						|
  {
 | 
						|
    if (to == startpos)
 | 
						|
    {
 | 
						|
      bmove(buff,(char*) name,length);		/* Save name for last copy */
 | 
						|
      name=buff;
 | 
						|
    }
 | 
						|
    pos=strmake(strmov(to,dev),name,length);
 | 
						|
    (void) strmov(pos,ext);			/* Don't convert extension */
 | 
						|
  }
 | 
						|
  /*
 | 
						|
    If MY_RETURN_REAL_PATH and MY_RESOLVE_SYMLINK is given, only do
 | 
						|
    realpath if the file is a symbolic link
 | 
						|
  */
 | 
						|
  if (flag & MY_RETURN_REAL_PATH)
 | 
						|
    (void) my_realpath(to, to, MYF(flag & MY_RESOLVE_SYMLINKS ?
 | 
						|
				   MY_RESOLVE_LINK: 0));
 | 
						|
  else if (flag & MY_RESOLVE_SYMLINKS)
 | 
						|
  {
 | 
						|
    strmov(buff,to);
 | 
						|
    (void) my_readlink(to, buff, MYF(0));
 | 
						|
  }
 | 
						|
  DBUG_RETURN(to);
 | 
						|
} /* fn_format */
 | 
						|
 | 
						|
 | 
						|
	/*
 | 
						|
	  strlength(const string str)
 | 
						|
	  Return length of string with end-space:s not counted.
 | 
						|
	  */
 | 
						|
 | 
						|
size_s strlength(const char *str)
 | 
						|
{
 | 
						|
  reg1 my_string pos;
 | 
						|
  reg2 my_string found;
 | 
						|
  DBUG_ENTER("strlength");
 | 
						|
 | 
						|
  pos=found=(char*) str;
 | 
						|
 | 
						|
  while (*pos)
 | 
						|
  {
 | 
						|
    if (*pos != ' ')
 | 
						|
    {
 | 
						|
      while (*++pos && *pos != ' ') {};
 | 
						|
      if (!*pos)
 | 
						|
      {
 | 
						|
	found=pos;			/* String ends here */
 | 
						|
	break;
 | 
						|
      }
 | 
						|
    }
 | 
						|
    found=pos;
 | 
						|
    while (*++pos == ' ') {};
 | 
						|
  }
 | 
						|
  DBUG_RETURN((size_s) (found-(char*) str));
 | 
						|
} /* strlength */
 |