diff --git a/libisofs/filesrc.c b/libisofs/filesrc.c index 239eb7a..79e73f9 100644 --- a/libisofs/filesrc.c +++ b/libisofs/filesrc.c @@ -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 */ diff --git a/libisofs/stream.c b/libisofs/stream.c index 9d315c6..c264065 100644 --- a/libisofs/stream.c +++ b/libisofs/stream.c @@ -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 diff --git a/libisofs/stream.h b/libisofs/stream.h index 0a81a03..1261b37 100644 --- a/libisofs/stream.h +++ b/libisofs/stream.h @@ -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);