Add a function to identify a Stream, for user notification.

release-1.5.4.branch
Vreixo Formoso 15 years ago
parent 5b856cf40b
commit c915c6e3f4
  1. 14
      src/filesrc.c
  2. 10
      src/stream.c
  3. 13
      src/stream.h

@ -237,9 +237,10 @@ int filesrc_writer_write_data(IsoImageWriter *writer)
* UPS, very ugly error, the best we can do is just to write
* 0's to image
*/
// TODO Stream needs a get_path function
iso_msg_sorry(t->image, LIBISO_FILE_CANT_WRITE,
"File XXX can't be openned. Filling with 0s.");
char *name = iso_stream_get_name(file->stream);
iso_msg_sorry(t->image, LIBISO_FILE_CANT_WRITE, "File \"%s\" can't"
" be opened. Filling with 0s.", name);
free(name);
memset(buffer, 0, BLOCK_SIZE);
for (b = 0; b < nblocks; ++b) {
res = iso_write(t, buffer, BLOCK_SIZE);
@ -264,15 +265,18 @@ int filesrc_writer_write_data(IsoImageWriter *writer)
if (b < nblocks) {
/* premature end of file, due to error or eof */
char *name = iso_stream_get_name(file->stream);
if (res < 0) {
/* error */
iso_msg_sorry(t->image, LIBISO_FILE_CANT_WRITE,
"Read error in file XXXXX.");
"Read error in file %s.", name);
} else {
/* eof */
iso_msg_sorry(t->image, LIBISO_FILE_CANT_WRITE,
"Premature end of file XXXXX.");
"Premature end of file %s.", name);
}
free(name);
/* fill with 0s */
iso_msg_sorry(t->image, LIBISO_FILE_CANT_WRITE, "Filling with 0");
memset(buffer, 0, BLOCK_SIZE);

@ -12,6 +12,7 @@
#include "error.h"
#include <stdlib.h>
#include <string.h>
typedef struct
{
@ -112,6 +113,14 @@ int fsrc_get_id(IsoStream *stream, unsigned int *fs_id, dev_t *dev_id,
return ISO_SUCCESS;
}
static
char *fsrc_get_name(IsoStream *stream)
{
FSrcStreamData *data;
data = (FSrcStreamData*)stream->data;
return strdup(iso_file_source_get_path(data->src));
}
static
void fsrc_free(IsoStream *stream)
{
@ -128,6 +137,7 @@ IsoStreamIface fsrc_stream_class = {
fsrc_read,
fsrc_is_repeatable,
fsrc_get_id,
fsrc_get_name,
fsrc_free
};

@ -80,6 +80,13 @@ typedef struct IsoStream_Iface
int (*get_id)(IsoStream *stream, unsigned int *fs_id, dev_t *dev_id,
ino_t *ino_id);
/**
* Get a name that identifies the Stream contents. It is used only for
* informational or debug purposes, so you can return anything you
* consider suitable for identification of the source, such as the path.
*/
char *(*get_name)(IsoStream *stream);
/**
* Free implementation specific data. Should never be called by user.
* Use iso_stream_unref() instead.
@ -134,6 +141,12 @@ int iso_stream_get_id(IsoStream *stream, unsigned int *fs_id, dev_t *dev_id,
return stream->class->get_id(stream, fs_id, dev_id, ino_id);
}
extern inline
char *iso_stream_get_name(IsoStream *stream)
{
return stream->class->get_name(stream);
}
/**
* Create a stream to read from a IsoFileSource.
* The stream will take the ref. to the IsoFileSource, so after a successfully

Loading…
Cancel
Save