Skip to content
Snippets Groups Projects
Commit c126d5ac authored by fjhenigman's avatar fjhenigman Committed by Jean-Baptiste Kempf
Browse files

Fix directory existence check.


mkdir() followed by errno==EEXIST is not sufficient to determine if
a directory exists.  Do a stat() to check for existence before trying
mkdir().

Signed-off-by: default avatarFrank Henigman <fjhenigman@gmail.com>
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 5bec036c
No related branches found
No related tags found
No related merge requests found
......@@ -143,6 +143,16 @@
#define MANUFACTURING_DATE_OFFSET 813
#define MANUFACTURING_DATE_LENGTH 16
static int exists_or_mkdir( const char *path, int perm )
{
/* mkdir() may return an error if making the directory would fail,
* even if the directory exists, so use stat() to test for existence
* before trying to make the directory. */
struct stat st;
if( stat(path, &st) )
return mkdir(path, perm);
return 0;
}
static dvdcss_t dvdcss_open_common ( const char *psz_target, void *p_stream,
dvdcss_stream_cb *p_stream_cb );
......@@ -221,7 +231,7 @@ static int set_cache_directory( dvdcss_t dvdcss )
* directory in userland */
char *psz_home = "/sdcard/Android/data/org.videolan.dvdcss";
int i_ret = mkdir( psz_home, 0755 );
int i_ret = exists_or_mkdir( psz_home, 0755 );
if( i_ret < 0 && errno != EEXIST )
{
print_error( dvdcss, "failed creating home directory" );
......@@ -302,7 +312,7 @@ static int init_cache_dir( dvdcss_t dvdcss )
char psz_tagfile[PATH_MAX];
int i_fd, i_ret;
i_ret = mkdir( dvdcss->psz_cachefile, 0755 );
i_ret = exists_or_mkdir( dvdcss->psz_cachefile, 0755 );
if( i_ret < 0 && errno != EEXIST )
{
print_error( dvdcss, "failed creating cache directory '%s'", dvdcss->psz_cachefile );
......@@ -425,7 +435,7 @@ static void create_cache_subdir( dvdcss_t dvdcss )
/* We have a disc name or ID, we can create the cache subdirectory. */
i = sprintf( dvdcss->psz_cachefile, "%s/%s-%s-%s",
dvdcss->psz_cachefile, psz_title, psz_serial, psz_key );
i_ret = mkdir( dvdcss->psz_cachefile, 0755 );
i_ret = exists_or_mkdir( dvdcss->psz_cachefile, 0755 );
if( i_ret < 0 && errno != EEXIST )
{
print_error( dvdcss, "failed creating cache subdirectory" );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment