Commit e1b883b2 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Handle I/O errors properly

(disk full?)
parent f46a9806
...@@ -39,6 +39,7 @@ int input_FindArtInCache( playlist_t *p_playlist, input_item_t *p_item ); ...@@ -39,6 +39,7 @@ int input_FindArtInCache( playlist_t *p_playlist, input_item_t *p_item );
vlc_bool_t input_MetaSatisfied( playlist_t *p_playlist, input_item_t *p_item, vlc_bool_t input_MetaSatisfied( playlist_t *p_playlist, input_item_t *p_item,
uint32_t *pi_mandatory, uint32_t *pi_optional ) uint32_t *pi_mandatory, uint32_t *pi_optional )
{ {
(void)p_playlist;
*pi_mandatory = VLC_META_ENGINE_TITLE | VLC_META_ENGINE_ARTIST; *pi_mandatory = VLC_META_ENGINE_TITLE | VLC_META_ENGINE_ARTIST;
assert( p_item->p_meta ); assert( p_item->p_meta );
...@@ -250,18 +251,28 @@ int input_DownloadAndCacheArt( playlist_t *p_playlist, input_item_t *p_item ) ...@@ -250,18 +251,28 @@ int input_DownloadAndCacheArt( playlist_t *p_playlist, input_item_t *p_item )
p_stream = stream_UrlNew( p_playlist, p_item->p_meta->psz_arturl ); p_stream = stream_UrlNew( p_playlist, p_item->p_meta->psz_arturl );
if( p_stream ) if( p_stream )
{ {
void *p_buffer = malloc( 1<<16 ); uint8_t p_buffer[65536];
long int l_read; long int l_read;
FILE *p_file = utf8_fopen( psz_filename+7, "w" ); FILE *p_file = utf8_fopen( psz_filename+7, "w" );
while( ( l_read = stream_Read( p_stream, p_buffer, 1<<16 ) ) ) int err = 0;
while( ( l_read = stream_Read( p_stream, p_buffer, sizeof (p_buffer) ) ) )
{ {
fwrite( p_buffer, l_read, 1, p_file ); if( fwrite( p_buffer, l_read, 1, p_file ) != 1 )
{
err = errno;
break;
}
} }
free( p_buffer ); if( fclose( p_file ) && !err )
fclose( p_file ); err = errno;
stream_Delete( p_stream ); stream_Delete( p_stream );
msg_Dbg( p_playlist, "album art saved to %s\n", psz_filename );
free( p_item->p_meta->psz_arturl ); free( p_item->p_meta->psz_arturl );
if( err )
msg_Err( p_playlist, "%s: %s", psz_filename, strerror( err ) );
else
msg_Dbg( p_playlist, "album art saved to %s\n", psz_filename );
p_item->p_meta->psz_arturl = strdup( psz_filename ); p_item->p_meta->psz_arturl = strdup( psz_filename );
i_status = VLC_SUCCESS; i_status = VLC_SUCCESS;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment