[easytag] Improve MP4 file error handling
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag] Improve MP4 file error handling
- Date: Tue, 21 May 2013 07:18:24 +0000 (UTC)
commit b4ef8260a60d7a7642728cd01e58624b5343fef4
Author: David King <amigadave amigadave com>
Date: Tue May 21 08:16:45 2013 +0100
Improve MP4 file error handling
Do not check if the file exists before reading or writing tags to the
file, but handle errors if they occur and return an appropriate result
on failure. Remove some unused includes.
src/mp4_tag.c | 33 +++------------------------------
1 files changed, 3 insertions(+), 30 deletions(-)
---
diff --git a/src/mp4_tag.c b/src/mp4_tag.c
index 9687df1..48f55f3 100644
--- a/src/mp4_tag.c
+++ b/src/mp4_tag.c
@@ -20,19 +20,12 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-/* Portions of this code was borrowed from the MPEG4IP tools project */
#include "config.h" // For definition of ENABLE_MP4
#ifdef ENABLE_MP4
#include <gtk/gtk.h>
#include <glib/gi18n-lib.h>
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <ctype.h>
-#include <unistd.h>
-#include <string.h>
#include <stdlib.h>
#include "mp4_tag.h"
@@ -58,22 +51,12 @@
*/
gboolean Mp4tag_Read_File_Tag (gchar *filename, File_Tag *FileTag)
{
- FILE *file;
TagLib_File *mp4file;
TagLib_Tag *tag;
guint track;
g_return_val_if_fail (filename != NULL && FileTag != NULL, FALSE);
- if ( (file=fopen(filename,"r"))==NULL )
- {
- gchar *filename_utf8 = filename_to_display(filename);
- Log_Print(LOG_ERROR,_("Error while opening file: '%s' (%s)."),filename_utf8,g_strerror(errno));
- g_free(filename_utf8);
- return FALSE;
- }
- fclose(file); // We close it cause mp4 opens/closes file itself
-
/* Get data from tag */
mp4file = taglib_file_new_type(filename,TagLib_File_MP4);
if (mp4file == NULL)
@@ -186,10 +169,9 @@ gboolean Mp4tag_Write_File_Tag (ET_File *ETFile)
File_Tag *FileTag;
gchar *filename;
gchar *filename_utf8;
- FILE *file;
TagLib_File *mp4file = NULL;
TagLib_Tag *tag;
- gint error = 0;
+ gboolean success;
g_return_val_if_fail (ETFile != NULL || ETFile->FileTag != NULL, FALSE);
@@ -197,14 +179,6 @@ gboolean Mp4tag_Write_File_Tag (ET_File *ETFile)
filename = ((File_Name *)ETFile->FileNameCur->data)->value;
filename_utf8 = ((File_Name *)ETFile->FileNameCur->data)->value_utf8;
- /* Test to know if we can write into the file */
- if ( (file=fopen(filename,"r+"))==NULL )
- {
- Log_Print(LOG_ERROR,_("Error while opening file: '%s' (%s)."),filename_utf8,g_strerror(errno));
- return FALSE;
- }
- fclose(file);
-
/* Open file for writing */
mp4file = taglib_file_new_type(filename, TagLib_File_MP4);
if (mp4file == NULL)
@@ -314,11 +288,10 @@ gboolean Mp4tag_Write_File_Tag (ET_File *ETFile)
* Picture *
***********/
- taglib_file_save(mp4file);
+ success = taglib_file_save (mp4file) ? TRUE : FALSE;
taglib_file_free(mp4file);
- if (error) return FALSE;
- else return TRUE;
+ return success;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]