diff options
Diffstat (limited to 'libid3tag')
-rw-r--r-- | libid3tag/file.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/libid3tag/file.c b/libid3tag/file.c index 8c1aa54..1feb504 100644 --- a/libid3tag/file.c +++ b/libid3tag/file.c @@ -727,8 +727,6 @@ v2_write(struct id3_file *file, { int rc; - if (file->ntags == 0) - return 0; if (data && ((file->ntags == 1 && !(file->flags & ID3_FILE_FLAG_ID3V1)) || (file->ntags == 2 && (file->flags & ID3_FILE_FLAG_ID3V1))) && @@ -769,14 +767,17 @@ v2_write(struct id3_file *file, * FIXME: Should I check * tag->version instead? */ - (file->tags[0].location == 0) ? + (file->ntags > 0 && + file->tags[0].location == 0) ? file->tags[0].length : 0, -1); fclose(tmp); if (rc) unlink(tmpname); else { - file->tags[0].length = length; + if (file->ntags > 0) + file->tags[0].length = length; + fclose(file->iofile); rc = unlink(file->path); if (rc == 0) { @@ -784,6 +785,11 @@ v2_write(struct id3_file *file, chmod(file->path, st.st_mode & 0777); chown(file->path, st.st_uid, st.st_gid); file->iofile = fopen(file->path, "r+b"); + if (file->ntags == 0) + add_tag(file, length); + /* FIXME: See also comment after the + call to this function in id3_file_update. + */ } } free(tmpname); @@ -798,13 +804,9 @@ v2_write(struct id3_file *file, int id3_file_update(struct id3_file *file) { - int options, - result = 0; - id3_length_t v1size = 0, - v2size = 0; - id3_byte_t id3v1_data[128], - *id3v1 = 0, - *id3v2 = 0; + int options, result = 0; + id3_length_t v1size = 0, v2size = 0; + id3_byte_t id3v1_data[128], *id3v1 = 0, *id3v2 = 0; assert(file); |