[libdvdcss-devel] [PATCH 40/47] libdvdcss: Factor out writing cache directory tag from dvdcss_open()

Diego Biurrun diego at biurrun.de
Wed Oct 29 21:33:40 CET 2014


---

I think this is broken, the cache directory does not exist on the
first invocation of libdvdcss.

 src/libdvdcss.c | 45 +++++++++++++++++++++++++--------------------
 1 file changed, 25 insertions(+), 20 deletions(-)

diff --git a/src/libdvdcss.c b/src/libdvdcss.c
index 4e78da1..dc27d69 100644
--- a/src/libdvdcss.c
+++ b/src/libdvdcss.c
@@ -269,6 +269,30 @@ static char *set_cache_directory( dvdcss_t dvdcss )
     return psz_cache;
 }
 
+static void write_cache_dir_tag( dvdcss_t dvdcss, const char *psz_cache )
+{
+    static const char psz_tag[] =
+        "Signature: 8a477f597d28d172789f06886806bc55\r\n"
+        "# This file is a cache directory tag created by libdvdcss.\r\n"
+        "# For information about cache directory tags, see:\r\n"
+        "#   http://www.brynosaurus.com/cachedir/\r\n";
+    char psz_tagfile[PATH_MAX + 1 + 12 + 1];
+    int i_fd;
+
+    sprintf( psz_tagfile, "%s/CACHEDIR.TAG", psz_cache );
+    i_fd = open( psz_tagfile, O_RDWR|O_CREAT, 0644 );
+    if( i_fd >= 0 )
+    {
+        ssize_t len = strlen(psz_tag);
+        if( write( i_fd, psz_tag, len ) < len )
+        {
+            print_error( dvdcss,
+                         "Error writing cache directory tag, continuing..\n" );
+        }
+        close( i_fd );
+    }
+}
+
 /**
  * \brief Open a DVD device or directory and return a dvdcss instance.
  *
@@ -370,26 +394,7 @@ LIBDVDCSS_EXPORT dvdcss_t dvdcss_open ( const char *psz_target )
     /* If the cache is enabled, write the cache directory tag */
     if( psz_cache )
     {
-        static const char psz_tag[] =
-            "Signature: 8a477f597d28d172789f06886806bc55\r\n"
-            "# This file is a cache directory tag created by libdvdcss.\r\n"
-            "# For information about cache directory tags, see:\r\n"
-            "#   http://www.brynosaurus.com/cachedir/\r\n";
-        char psz_tagfile[PATH_MAX + 1 + 12 + 1];
-        int i_fd;
-
-        sprintf( psz_tagfile, "%s/CACHEDIR.TAG", psz_cache );
-        i_fd = open( psz_tagfile, O_RDWR|O_CREAT, 0644 );
-        if( i_fd >= 0 )
-        {
-            ssize_t len = strlen(psz_tag);
-            if( write( i_fd, psz_tag, len ) < len )
-            {
-                print_error( dvdcss,
-                             "Error writing cache directory tag, continuing..\n" );
-            }
-            close( i_fd );
-        }
+        write_cache_dir_tag( dvdcss, psz_cache );
     }
 
     /* If the cache is enabled, extract a unique disc ID */
-- 
1.9.1



More information about the libdvdcss-devel mailing list