Detect size changes on files.

This commit is contained in:
Vreixo Formoso 2008-02-06 18:04:51 +01:00
parent 293e8ab2fc
commit 5088428742
3 changed files with 29 additions and 4 deletions

View File

@ -286,6 +286,16 @@ int filesrc_writer_write_data(IsoImageWriter *writer)
}
}
continue;
} else if (res > 1) {
char *name = iso_stream_get_name(file->stream);
res = iso_msg_submit(t->image->id, ISO_FILE_CANT_WRITE, 0,
"Size of file \"%s\" has changed. It will be %s", name,
(res == 2 ? "truncated" : "padded with 0's"));
free(name);
if (res < 0) {
filesrc_close(file);
return res; /* aborted due to error severity */
}
}
/* write file contents to image */

View File

@ -30,12 +30,28 @@ typedef struct
static
int fsrc_open(IsoStream *stream)
{
int ret;
struct stat info;
off_t esize;
IsoFileSource *src;
if (stream == NULL) {
return ISO_NULL_POINTER;
}
src = ((FSrcStreamData*)stream->data)->src;
return iso_file_source_open(src);
ret = iso_file_source_stat(src, &info);
if (ret < 0) {
return ret;
}
ret = iso_file_source_open(src);
if (ret < 0) {
return ret;
}
esize = ((FSrcStreamData*)stream->data)->size;
if (info.st_size == esize) {
return ISO_SUCCESS;
} else {
return (esize > info.st_size) ? 3 : 2;
}
}
static

View File

@ -32,10 +32,9 @@ typedef struct IsoStream_Iface
/**
* Opens the stream.
*
* TODO it would be great to return a different success code if the
* underlying source size has changed.
* @return
* 1 on success, < 0 on error
* 1 on success, 2 file greater than expected, 3 file smaller than
* expected, < 0 on error
*/
int (*open)(IsoStream *stream);