changeset 7721:765afc1fcd67

Create the ~/.cddb directory if not present.
author bertrand
date Sun, 13 Oct 2002 08:27:03 +0000
parents c6aa14b47d03
children a181875e0aa8
files libmpdemux/cddb.c
diffstat 1 files changed, 17 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/cddb.c	Sun Oct 13 00:30:38 2002 +0000
+++ b/libmpdemux/cddb.c	Sun Oct 13 08:27:03 2002 +0000
@@ -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