Commit da4abd2e authored by unknown's avatar unknown
Browse files

Merge pilot.blaudden:/home/msvensson/mysql/mysql-4.1-maint

into  pilot.blaudden:/home/msvensson/mysql/mysql-5.0-maint


client/mysqltest.c:
  Auto merged
mysql-test/t/mysqltest.test:
  Auto merged
parents 485ab9a4 f10cfb05
Loading
Loading
Loading
Loading
+75 −1
Original line number Diff line number Diff line
@@ -273,7 +273,7 @@ enum enum_commands {
  Q_DISABLE_PARSING, Q_ENABLE_PARSING,
  Q_REPLACE_REGEX, Q_REMOVE_FILE, Q_FILE_EXIST,
  Q_WRITE_FILE, Q_COPY_FILE, Q_PERL, Q_DIE, Q_EXIT,
  Q_CHMOD_FILE, Q_APPEND_FILE, Q_CAT_FILE,
  Q_CHMOD_FILE, Q_APPEND_FILE, Q_CAT_FILE, Q_DIFF_FILES,

  Q_UNKNOWN,			       /* Unknown command.   */
  Q_COMMENT,			       /* Comments, ignored. */
@@ -360,6 +360,7 @@ const char *command_names[]=
  "chmod",
  "append_file",
  "cat_file",
  "diff_files",
  0
};

@@ -2242,6 +2243,78 @@ void do_cat_file(struct st_command *command)
}



/*
  SYNOPSIS
  do_diff_files
  command	called command

  DESCRIPTION
  diff_files <file1> <file2>;

  Fails if the two files differ.

*/

void do_diff_files(struct st_command *command)
{
  int error= 0;
  int fd, fd2;
  uint len, len2;
  char buff[512], buff2[512];
  static DYNAMIC_STRING ds_filename;
  static DYNAMIC_STRING ds_filename2;
  const struct command_arg diff_file_args[] = {
    "file1", ARG_STRING, TRUE, &ds_filename, "First file to diff",
    "file2", ARG_STRING, TRUE, &ds_filename2, "Second file to diff"
  };
  DBUG_ENTER("do_diff_files");

  check_command_args(command,
                     command->first_argument,
                     diff_file_args,
                     sizeof(diff_file_args)/sizeof(struct command_arg),
                     ' ');

  if ((fd= my_open(ds_filename.str, O_RDONLY, MYF(0))) < 0)
    die("Failed to open first file %s", ds_filename.str);
  if ((fd2= my_open(ds_filename2.str, O_RDONLY, MYF(0))) < 0)
  {
    my_close(fd, MYF(0));
    die("Failed to open second file %s", ds_filename2.str);
  }
  while((len= my_read(fd, (byte*)&buff,
                      sizeof(buff), MYF(0))) > 0)
  {
    if ((len2= my_read(fd2, (byte*)&buff2,
                       sizeof(buff2), MYF(0))) != len)
    {
      /* File 2 was smaller */
      error= 1;
      break;
    }
    if ((memcmp(buff, buff2, len)))
    {
      /* Content of this part differed */
      error= 1;
      break;
    }
  }
  if (my_read(fd2, (byte*)&buff2,
              sizeof(buff2), MYF(0)) > 0)
  {
    /* File 1 was smaller */
    error= 1;
  }

  my_close(fd, MYF(0));
  my_close(fd2, MYF(0));
  dynstr_free(&ds_filename);
  dynstr_free(&ds_filename2);
  handle_command_error(command, error);
  DBUG_VOID_RETURN;
}

/*
  SYNOPSIS
  do_perl
@@ -6019,6 +6092,7 @@ int main(int argc, char **argv)
      case Q_FILE_EXIST: do_file_exist(command); break;
      case Q_WRITE_FILE: do_write_file(command); break;
      case Q_APPEND_FILE: do_append_file(command); break;
      case Q_DIFF_FILES: do_diff_files(command); break;
      case Q_CAT_FILE: do_cat_file(command); break;
      case Q_COPY_FILE: do_copy_file(command); break;
      case Q_CHMOD_FILE: do_chmod_file(command); break;
+35 −0
Original line number Diff line number Diff line
@@ -1563,6 +1563,41 @@ cat_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
--error 1
--exec echo "cat_file non_existing_file;" | $MYSQL_TEST 2>&1

# ----------------------------------------------------------------------------
# test for diff_files
# ----------------------------------------------------------------------------

--write_file $MYSQLTEST_VARDIR/tmp/diff1.tmp
Some data
for diff_file command
of mysqltest
EOF

--write_file $MYSQLTEST_VARDIR/tmp/diff2.tmp
Some data
for diff_file command
of mysqltest
EOF

--write_file $MYSQLTEST_VARDIR/tmp/diff3.tmp
Some other data
for diff_file command
of mysqltest
EOF

# Compare equal files
--diff_files $MYSQLTEST_VARDIR/tmp/diff1.tmp $MYSQLTEST_VARDIR/tmp/diff2.tmp
--diff_files $MYSQLTEST_VARDIR/tmp/diff2.tmp $MYSQLTEST_VARDIR/tmp/diff1.tmp

# Compare files that differ
--error 1
--diff_files $MYSQLTEST_VARDIR/tmp/diff3.tmp $MYSQLTEST_VARDIR/tmp/diff2.tmp
--error 1
--diff_files $MYSQLTEST_VARDIR/tmp/diff1.tmp $MYSQLTEST_VARDIR/tmp/diff3.tmp

# Compare equal files, again...
--diff_files $MYSQLTEST_VARDIR/tmp/diff1.tmp $MYSQLTEST_VARDIR/tmp/diff2.tmp

# ----------------------------------------------------------------------------
# test for file_exist
# ----------------------------------------------------------------------------