Detect size changes on files.
This commit is contained in:
parent
293e8ab2fc
commit
5088428742
@ -286,6 +286,16 @@ int filesrc_writer_write_data(IsoImageWriter *writer)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
continue;
|
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 */
|
/* write file contents to image */
|
||||||
|
@ -30,12 +30,28 @@ typedef struct
|
|||||||
static
|
static
|
||||||
int fsrc_open(IsoStream *stream)
|
int fsrc_open(IsoStream *stream)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
|
struct stat info;
|
||||||
|
off_t esize;
|
||||||
IsoFileSource *src;
|
IsoFileSource *src;
|
||||||
if (stream == NULL) {
|
if (stream == NULL) {
|
||||||
return ISO_NULL_POINTER;
|
return ISO_NULL_POINTER;
|
||||||
}
|
}
|
||||||
src = ((FSrcStreamData*)stream->data)->src;
|
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
|
static
|
||||||
|
@ -32,10 +32,9 @@ typedef struct IsoStream_Iface
|
|||||||
/**
|
/**
|
||||||
* Opens the stream.
|
* Opens the stream.
|
||||||
*
|
*
|
||||||
* TODO it would be great to return a different success code if the
|
|
||||||
* underlying source size has changed.
|
|
||||||
* @return
|
* @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);
|
int (*open)(IsoStream *stream);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user