comparison libmpdemux/cddb.c @ 7721:765afc1fcd67

Create the ~/.cddb directory if not present.
author bertrand
date Sun, 13 Oct 2002 08:27:03 +0000
parents e46eeafcd4df
children 15ce89ba92cf
comparison
equal deleted inserted replaced
7720:c6aa14b47d03 7721:765afc1fcd67
285 } 285 }
286 286
287 int 287 int
288 cddb_write_cache(cddb_data_t *cddb_data) { 288 cddb_write_cache(cddb_data_t *cddb_data) {
289 // We have the file, save it for cache. 289 // We have the file, save it for cache.
290 struct stat file_stat;
290 char file_name[100]; 291 char file_name[100];
291 int file_fd; 292 int file_fd, ret;
292 size_t wrote=0; 293 size_t wrote=0;
293 294
294 if( cddb_data==NULL || cddb_data->cache_dir==NULL ) return -1; 295 if( cddb_data==NULL || cddb_data->cache_dir==NULL ) return -1;
295 296
296 sprintf( file_name, "%s%08lx", cddb_data->cache_dir, cddb_data->disc_id); 297 // Check if the CDDB cache dir exist
298 ret = stat( cddb_data->cache_dir, &file_stat );
299 if( ret<0 ) {
300 // Directory not present, create it.
301 ret = mkdir( cddb_data->cache_dir, 0755 );
302 if( ret<0 ) {
303 perror("mkdir");
304 printf("Failed to create directory %s\n", cddb_data->cache_dir );
305 return -1;
306 }
307 }
308
309 sprintf( file_name, "%s%08lx", cddb_data->cache_dir, cddb_data->disc_id );
297 310
298 file_fd = creat(file_name, S_IREAD|S_IWRITE); 311 file_fd = creat(file_name, S_IREAD|S_IWRITE);
299 if( file_fd<0 ) { 312 if( file_fd<0 ) {
300 perror("open"); 313 perror("create");
301 return -1; 314 return -1;
302 } 315 }
303 316
304 wrote = write(file_fd, cddb_data->xmcd_file, cddb_data->xmcd_file_size); 317 wrote = write(file_fd, cddb_data->xmcd_file, cddb_data->xmcd_file_size);
305 if( wrote<0 ) { 318 if( wrote<0 ) {
749 762
750 ret = cddb_resolve(&xmcd_file); 763 ret = cddb_resolve(&xmcd_file);
751 if( ret==0 ) { 764 if( ret==0 ) {
752 cd_info = cddb_parse_xmcd(xmcd_file); 765 cd_info = cddb_parse_xmcd(xmcd_file);
753 free(xmcd_file); 766 free(xmcd_file);
754 cd_info_debug( cd_info );
755 } 767 }
756 stream = open_cdda(dev, track); 768 stream = open_cdda(dev, track);
757 769
758 priv = ((cdda_priv*)(stream->priv)); 770 priv = ((cdda_priv*)(stream->priv));
759 cd_info_debug(priv->cd_info);
760 if( cd_info!=NULL ) { 771 if( cd_info!=NULL ) {
761 cd_info_free(priv->cd_info); 772 cd_info_free(priv->cd_info);
762 priv->cd_info = cd_info; 773 priv->cd_info = cd_info;
763 } 774 }
775 cd_info_debug( cd_info );
764 return stream; 776 return stream;
765 } 777 }
766 #endif 778 #endif