/* Create a temporary file in tmpdir. The file will be automatically
removed on close. Code copied from mysql_tmpfile(). */
fd = create_temp_file(tmp_path,xtrabackup_tmpdir, "xbtemp", O_BINARY | O_SEQUENTIAL,
MYF(MY_WME | MY_TEMPORARY));
tmp_file = (ds_tmp_file_t *) (file + 1);
tmp_file->file = file;
memcpy(&tmp_file->mystat, mystat, sizeof(MY_STAT)); /* Save a copy of 'path', since it may not be accessible later */
tmp_file->orig_path = (char *) tmp_file + sizeof(ds_tmp_file_t);
if (my_write(fd, buf, len, MYF(MY_WME | MY_NABP))) { return1;
}
return0;
}
staticint
tmpfile_close(ds_file_t *file)
{ /* Do nothing -- we will close (and thus remove) the file after piping
it to the destination datasink in tmpfile_deinit(). */
tmpfile_ctxt = (ds_tmpfile_ctxt_t *) ctxt->ptr;
list = tmpfile_ctxt->file_list;
/* Walk the files in the order they have been added */
list = list_reverse(list); while (list != NULL) {
tmp_file = (ds_tmp_file_t *)list->data; /* Stat the file to replace size and mtime on the original
* mystat struct */ if (my_fstat(tmp_file->fd, &mystat, MYF(0))) {
die("my_fstat() failed.");
}
tmp_file->mystat.st_size = mystat.st_size;
tmp_file->mystat.st_mtime = mystat.st_mtime;
dst_file = ds_open(pipe_ctxt, tmp_file->orig_path,
&tmp_file->mystat); if (dst_file == NULL) {
die("could not stream a temporary file to " "'%s'", tmp_file->orig_path);
}
/* copy to the destination datasink */
posix_fadvise(tmp_file->fd, 0, 0, POSIX_FADV_SEQUENTIAL); if (my_seek(tmp_file->fd, 0, SEEK_SET, MYF(0)) ==
MY_FILEPOS_ERROR) {
die("my_seek() failed for '%s', errno = %d.",
tmp_file->file->path, my_errno);
}
offset = 0; while ((bytes = my_read(tmp_file->fd, (unsignedchar *)buf, buf_size,
MYF(MY_WME))) > 0) {
posix_fadvise(tmp_file->fd, offset, buf_size, POSIX_FADV_DONTNEED);
offset += buf_size; if (ds_write(dst_file, buf, bytes)) {
die("cannot write to stream for '%s'.",
tmp_file->orig_path);
}
} if (bytes == (size_t) -1) {
die("my_read failed for %s", tmp_file->orig_path);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.