Added iso_image_update_sizes() API.

This requires increasing IsoStreamIface version, as we need to add a new 
method on it. API/ABI remains compatible with older version.
This commit is contained in:
Vreixo Formoso 2008-09-07 16:32:18 +02:00
parent e79ee64a2f
commit 68419703d7
5 changed files with 135 additions and 24 deletions

View File

@ -1,4 +1,4 @@
#Tue Aug 19 23:58:44 CEST 2008 #Sat Sep 06 00:52:28 CEST 2008
eclipse.preferences.version=1 eclipse.preferences.version=1
indexer/filesToParseUpFront= indexer/filesToParseUpFront=
indexer/indexAllFiles=true indexer/indexAllFiles=true

View File

@ -275,3 +275,36 @@ int iso_image_get_msg_id(IsoImage *image)
{ {
return image->id; return image->id;
} }
static
int dir_update_size(IsoImage *image, IsoDir *dir)
{
IsoNode *pos;
pos = dir->children;
while (pos) {
int ret = 1;
if (pos->type == LIBISO_FILE) {
ret = iso_stream_update_size(ISO_FILE(pos)->stream);
} else if (pos->type == LIBISO_DIR) {
/* recurse */
ret = dir_update_size(image, ISO_DIR(pos));
}
if (ret < 0) {
ret = iso_msg_submit(image->id, ret, 0, NULL);
if (ret < 0) {
return ret; /* cancel due error threshold */
}
}
pos = pos->next;
}
return ISO_SUCCESS;
}
int iso_image_update_sizes(IsoImage *image)
{
if (image == NULL) {
return ISO_NULL_POINTER;
}
return dir_update_size(image, image->root);
}

View File

@ -713,7 +713,12 @@ extern ino_t serial_id;
*/ */
struct IsoStream_Iface struct IsoStream_Iface
{ {
/* reserved for future usage, set to 0 */ /*
* Current version of the interface, set to 1.
*
* -version 1 (since 0.6.8)
* update_size() added.
*/
int version; int version;
/** /**
@ -743,7 +748,8 @@ struct IsoStream_Iface
/** /**
* Get the size (in bytes) of the stream. This function should always * Get the size (in bytes) of the stream. This function should always
* return the same size, even if the underlying source size changes. * return the same size, even if the underlying source size changes,
* unless you call update_size() method.
*/ */
off_t (*get_size)(IsoStream *stream); off_t (*get_size)(IsoStream *stream);
@ -785,6 +791,21 @@ struct IsoStream_Iface
* Use iso_stream_unref() instead. * Use iso_stream_unref() instead.
*/ */
void (*free)(IsoStream *stream); void (*free)(IsoStream *stream);
/**
* Updates the size of the IsoStream with the current size of the
* underlying source. After calling this, get_size() will return
* the new size. This should never be called after
* iso_image_create_burn_source() was called and the image was not
* completely written. To update the size of all files before written the
* image, you may want to call iso_image_update_sizes() just before
* iso_image_create_burn_source().
*
* @return
* 1 if ok, < 0 on error (has to be a valid libisofs error code)
* @since 0.6.8
*/
int (*update_size)(IsoStream *stream);
}; };
/** /**
@ -1318,6 +1339,20 @@ int iso_write_opts_set_fifo_size(IsoWriteOpts *opts, size_t fifo_size);
int iso_image_create_burn_source(IsoImage *image, IsoWriteOpts *opts, int iso_image_create_burn_source(IsoImage *image, IsoWriteOpts *opts,
struct burn_source **burn_src); struct burn_source **burn_src);
/**
* Update the sizes of all files added to image.
*
* This may be called just before iso_image_create_burn_source() to force
* libisofs to check the file sizes again (they're already checked when added
* to IsoImage). It is useful if you have changed some files after adding then
* to the image.
*
* @return
* 1 on success, < 0 on error
* @since 0.6.8
*/
int iso_image_update_sizes(IsoImage *image);
/** /**
* Creates an IsoReadOpts for reading an existent image. You should set the * Creates an IsoReadOpts for reading an existent image. You should set the
* options desired with the correspondent setters. Note that you may want to * options desired with the correspondent setters. Note that you may want to
@ -3660,7 +3695,8 @@ int iso_stream_close(IsoStream *stream);
/** /**
* Get the size of a given stream. This function should always return the same * Get the size of a given stream. This function should always return the same
* size, even if the underlying source size changes. * size, even if the underlying source size changes, unless you call
* iso_stream_update_size().
* *
* @return * @return
* IsoStream size in bytes * IsoStream size in bytes
@ -3699,6 +3735,17 @@ int iso_stream_read(IsoStream *stream, void *buf, size_t count);
*/ */
int iso_stream_is_repeatable(IsoStream *stream); int iso_stream_is_repeatable(IsoStream *stream);
/**
* Updates the size of the IsoStream with the current size of the
* underlying source.
*
* @return
* 1 if ok, < 0 on error (has to be a valid libisofs error code),
* 0 if the IsoStream does not support this function.
* @since 0.6.8
*/
int iso_stream_update_size(IsoStream *stream);
/** /**
* Get an unique identifier for a given IsoStream. * Get an unique identifier for a given IsoStream.
* *

View File

@ -124,8 +124,28 @@ void fsrc_free(IsoStream *stream)
free(data); free(data);
} }
static
int fsrc_update_size(IsoStream *stream)
{
int ret;
struct stat info;
IsoFileSource *src;
if (stream == NULL) {
return ISO_NULL_POINTER;
}
src = ((FSrcStreamData*)stream->data)->src;
ret = iso_file_source_stat(src, &info);
if (ret < 0) {
return ret;
}
((FSrcStreamData*)stream->data)->size = info.st_size;
return ISO_SUCCESS;
}
IsoStreamIface fsrc_stream_class = { IsoStreamIface fsrc_stream_class = {
0, 1, /* update_size is defined for this stream */
"fsrc", "fsrc",
fsrc_open, fsrc_open,
fsrc_close, fsrc_close,
@ -133,7 +153,8 @@ IsoStreamIface fsrc_stream_class = {
fsrc_read, fsrc_read,
fsrc_is_repeatable, fsrc_is_repeatable,
fsrc_get_id, fsrc_get_id,
fsrc_free fsrc_free,
fsrc_update_size
}; };
int iso_file_source_stream_new(IsoFileSource *src, IsoStream **stream) int iso_file_source_stream_new(IsoFileSource *src, IsoStream **stream)
@ -317,6 +338,9 @@ void cut_out_free(IsoStream *stream)
free(data); free(data);
} }
/*
* TODO update cut out streams to deal with update_size(). Seems hard.
*/
IsoStreamIface cut_out_stream_class = { IsoStreamIface cut_out_stream_class = {
0, 0,
"cout", "cout",
@ -587,6 +611,13 @@ int iso_stream_is_repeatable(IsoStream *stream)
return stream->class->is_repeatable(stream); return stream->class->is_repeatable(stream);
} }
inline
int iso_stream_update_size(IsoStream *stream)
{
IsoStreamIface* class = stream->class;
return (class->version >= 1) ? class->update_size(stream) : 0;
}
inline inline
void iso_stream_get_id(IsoStream *stream, unsigned int *fs_id, dev_t *dev_id, void iso_stream_get_id(IsoStream *stream, unsigned int *fs_id, dev_t *dev_id,
ino_t *ino_id) ino_t *ino_id)