[Mplayer-cvslog] CVS: main/libmpdemux cddb.c,1.5,1.6

Bertrand Baudet bertrand at mplayerhq.hu
Sun Oct 13 10:27:19 CEST 2002


Update of /cvsroot/mplayer/main/libmpdemux
In directory mail:/var/tmp.root/cvs-serv28719

Modified Files:
	cddb.c 
Log Message:
Create the ~/.cddb directory if not present.


Index: cddb.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/cddb.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- cddb.c	17 Sep 2002 19:51:12 -0000	1.5
+++ cddb.c	13 Oct 2002 08:27:03 -0000	1.6
@@ -287,17 +287,30 @@
 int
 cddb_write_cache(cddb_data_t *cddb_data) {
 	// We have the file, save it for cache.
+	struct stat file_stat;
 	char file_name[100];
-	int file_fd;
+	int file_fd, ret;
 	size_t wrote=0;
 
 	if( cddb_data==NULL || cddb_data->cache_dir==NULL ) return -1;
 
-	sprintf( file_name, "%s%08lx", cddb_data->cache_dir, cddb_data->disc_id);
+	// Check if the CDDB cache dir exist
+	ret = stat( cddb_data->cache_dir, &file_stat );
+	if( ret<0 ) {
+		// Directory not present, create it.
+		ret = mkdir( cddb_data->cache_dir, 0755 );
+		if( ret<0 ) {
+			perror("mkdir");
+			printf("Failed to create directory %s\n", cddb_data->cache_dir );
+			return -1;
+		}
+	}
+	
+	sprintf( file_name, "%s%08lx", cddb_data->cache_dir, cddb_data->disc_id );
 	
 	file_fd = creat(file_name, S_IREAD|S_IWRITE);
 	if( file_fd<0 ) {
-		perror("open");
+		perror("create");
 		return -1;
 	}
 	
@@ -751,16 +764,15 @@
 	if( ret==0 ) {
 		cd_info = cddb_parse_xmcd(xmcd_file);
 		free(xmcd_file);
-cd_info_debug( cd_info );	
 	}
 	stream = open_cdda(dev, track);
 
 	priv = ((cdda_priv*)(stream->priv));
-cd_info_debug(priv->cd_info);
 	if( cd_info!=NULL ) { 
 		cd_info_free(priv->cd_info);
 		priv->cd_info = cd_info;
 	}	
+cd_info_debug( cd_info );	
 	return stream;
 }
 #endif




More information about the MPlayer-cvslog mailing list