2006-08-21: EV dixit:
> I'll send the patch later tonight, hopefully after Franky has 
> updated the repository to changeset 105 with your latest patch.  
> Please wait for this one before sending new patches!

Find it attached.  Keith, please review the rio_rw.c changes
since I think they mainly affect code recently written by you.  
I have not dared to introduce the other changes I mentioned (as I
don't understand taglib sufficiently):

2006-08-21: EV dixit:
> [...] make some changes to rio_rw.c; mainly to avoid non-atomic
> setting of path-defining properties, which makes the virtual
> files just evaporate while calling taglib [...]

The idea is not to set any default genre, artist, source or title
*before* calling taglib.  Instead, wait to see if taglib doesn't
find values for these properties and set them to the defaults
(NOT_TAGGED for genre, artist and source and the filename for the
title).  The functions involved are: get_{ogg,flac,mp3}_props(),
add_general(), and set_tag_props(), where everything should go.

It seems fairly trivial, but I don't want to break something 
related with taglib.  So I leave it for you or Franky.  Thanks!

Best,
EV.
# HG changeset patch
# User [EMAIL PROTECTED]
# Node ID 522bb4748bb629d1519b2f65dd73aae88ee360e4
# Parent  4a14506c9f380bd2c88db9cc8c4e73b7a69996e3
Restored broken Ethernet functionality and fixed rio_rw bugs

diff -r 4a14506c9f38 -r 522bb4748bb6 ChangeLog
--- a/ChangeLog Mon Aug 21 14:45:21 2006
+++ b/ChangeLog Mon Aug 21 21:33:14 2006
@@ -1,5 +1,6 @@
 0.0.6:
-        * Fixed rio_rw error handling and several other minor bugs
+        * Re-implemented fdb support and made it functional
+        * Fixed rio_rw error handling and several other bugs
         * Added lk_rio_update_props_from_tags() to help lkarmafs file upload
        * Get file type from its contents rather than the suffix.
        * Use the rid property to (optionally) avoid multiple uploaded copies
diff -r 4a14506c9f38 -r 522bb4748bb6 src/errors.c
--- a/src/errors.c      Mon Aug 21 14:45:21 2006
+++ b/src/errors.c      Mon Aug 21 21:33:14 2006
@@ -51,7 +51,8 @@
     /* E_NOHASH    32 */ "** Libkarma error: no hash found",
     /* E_WRCHUNK   33 */ "** Libkarma error: write_file_chunk() failed",
     /* E_SMALLMP3  34 */ "** Libkarma error: tune file is too small",
-    /* E_UNSUPTAG  35 */ "* Libkarma warning: unsupported tag type"
+    /* E_UNSUPTAG  35 */ "* Libkarma warning: unsupported tag type",
+    /* E_NOTAGFILE 36 */ "* Libkarma warning: can't access tags file"
 };
 
 #define libkarmaErrorString lkerrorList[libkarmaError]
diff -r 4a14506c9f38 -r 522bb4748bb6 src/lkarma.h
--- a/src/lkarma.h      Mon Aug 21 14:45:21 2006
+++ b/src/lkarma.h      Mon Aug 21 21:33:14 2006
@@ -149,8 +149,9 @@
 #define E_WRCHUNK   33  /* error:   write_file_chunk() failed */  /* RIO_RW */
 #define E_SMALLMP3  34  /* error:   tune file is too small    */  /* RIO_RW */
 #define E_UNSUPTAG  35  /* warning: unsupported tag type      */  /* RIO_RW */
-
-#define MAXLKERRORS 35
+#define E_NOTAGFILE 36  /* warning: can't access tags file    */  /* RIO_RW */
+
+#define MAXLKERRORS 36
 
 
 /*
diff -r 4a14506c9f38 -r 522bb4748bb6 src/rio_rw.c
--- a/src/rio_rw.c      Mon Aug 21 14:45:21 2006
+++ b/src/rio_rw.c      Mon Aug 21 21:33:14 2006
@@ -133,16 +133,15 @@
     return 0;
 }
 
-static int lk_rio_do_update_props_from_tags(int fdb, int rio, uint32_t fid,
-                                            const char *fname)
+int lk_rio_update_props_from_tags(int rio, uint32_t fid, const char *fname)
 {
     int got=-1, usb=0;
-    char *rid, *filename;
     struct stat len;
     HASH * props;
+    mp3info mp3;
+    char *rid, *filename;
     int type, rid_fd;
-    mp3info mp3;
-    uint32_t *fids;
+/** uint32_t *fids; **/
 
     if (fname == NULL) {
         filename = lk_karma_fidToPath(rio, fid);
@@ -166,7 +165,8 @@
     rid = (char*)lk_generate_rid(rid_fd, mp3.offset, mp3.datasize);
     close(rid_fd);
 
-    if (write_dupes == 0 && fdb == 0) {
+/* This doesn't belong to update_props_from_tags: moved to lk_rio_do_write() */
+/** if (write_dupes == 0 && fdb == 0) {
         fids = lk_properties_andOrSearch(EXACT|ORS, NULL, "rid", rid);
 
         if (fids != NULL) {
@@ -178,7 +178,7 @@
             lk_errors_set(E_DUPE);
             return -1;
         }
-    }
+    } **/
 
     /* uses lk_properties_getnextfid()...*/
     props=lk_properties_idsearch(fid);
@@ -216,10 +216,11 @@
     return got;
 }
 
-int lk_rio_update_props_from_tags(int rio, uint32_t fid, const char *fname)
+/** No longer needed !! **/
+/** int lk_rio_update_props_from_tags(int rio, uint32_t fid, const char *fname)
 {
     return lk_rio_do_update_props_from_tags(0, rio, fid, fname);
-}
+} **/
 
 /*
      To use that function properly:
@@ -232,12 +233,11 @@
 static uint32_t lk_rio_do_write(int fdb, int rio, const char * filename)
 {
     int got, fd, len;
-    uint32_t fid = 0;
+    uint32_t fid = 0, *ids;
     uint64_t offs=0;
     char *p, tmp[BLOCKSIZE];
     const uint64_t siz=BLOCKSIZE;
-    char *path, fullpath[257+PATH_MAX];
-    uint32_t *ids;
+    char *rid, *path, fullpath[257+PATH_MAX];
 
     fd=open(filename, O_RDONLY);
     if (fd == -1)
@@ -256,25 +256,28 @@
     if (!fid)
         fid = lk_properties_new_property(); 
 
-    got = lk_rio_do_update_props_from_tags(fdb, rio, fid, filename);
-    if (got != 0)
+    got = lk_rio_update_props_from_tags(rio, fid, filename);
+    if (got != 0) {
         lk_properties_del_property(fid);
-
-    if (got != 0) {
         close(fd);
         return -1;
     }
 
-    while((got=read(fd, &tmp, siz)) > 0){
-        /*
-        if(got < siz) 
-            memset(&tmp[got], 0, (siz-got)%4);
-        if(lk_karma_write_file_chunk(rio, offs, got+((siz-got)%4),
-                                     fid, 0, tmp) != 0)
-        */
+    /** Brought here from lk_rio_update_props_from_tags() **/
+    rid = lk_properties_get_property(fid, "rid");
+    if (write_dupes == 0 && fdb == 0) {
+        ids = lk_properties_andOrSearch(EXACT|ORS, NULL, "rid", rid);
+        if ((ids != NULL) && (ids[1] != 0)) { /* more than 1 fid with this 
rid*/
+            free(ids);
+            lk_errors_set(E_DUPE);
+            lk_properties_del_property(fid);
+           return -1;
+       }
+    }
+
+    while((got=read(fd, &tmp, siz)) > 0) {  /* Now writting the data */
         if(lk_karma_write_file_chunk(rio, offs, got, fid, 0, tmp)!=0) {
            lk_errors_set(E_WRCHUNK);
-/*          printf("lk_karma_write_file_chunk: %u of %llu\n", got, siz); */
             lk_properties_del_property(fid);
             return -1;
         }
@@ -443,10 +446,20 @@
     TagLib_Tag *tl_tag;
     const TagLib_AudioProperties * tl_audio;
     int i;
+    int fdTestOpen;
     char bitrate[6];
     uint32_t *ids;
     char *title, *source, *artist;
 
+/** Test needed since taglib_file_new[_type] returns !NULL if its open fails */
+    fdTestOpen = open(filename, O_RDONLY);
+    if (fdTestOpen != -1) 
+        close(fdTestOpen);
+    else {
+        lk_errors_set(E_NOTAGFILE);
+        return 0;
+    }
+/** end Test */
     if (type != -1) 
         tl_file = taglib_file_new_type(filename, type);
     else
diff -r 4a14506c9f38 -r 522bb4748bb6 tools/riocp.c
--- a/tools/riocp.c     Mon Aug 21 14:45:21 2006
+++ b/tools/riocp.c     Mon Aug 21 21:33:14 2006
@@ -617,14 +617,14 @@
     lk_karma_get_device_settings(karma, &settings);
     dbChanged = lk_properties_cache_obsolete(settings);
     if(dbChanged) {
-        printf("Downloading Rio database... ");
+        fprintf(stderr, "Downloading Rio database... ");
         fflush(stdout);
-        if(getUsedSize(karma)>3E9) printf(" please wait... ");
-        fflush(stdout);
+        if(getUsedSize(karma)>3E9) fprintf(stderr, " please wait... ");
+        fflush(stderr);
     }
     free(settings);
     if(!r) lk_karma_load_database(karma);
-    if(dbChanged) printf("Done!\n");
+    if(dbChanged) fprintf(stderr, "Done!\n");
 
     if(fdbDownload)
         fdb_download(checkHost);
@@ -664,26 +664,24 @@
         } else fprintf(stderr, "No files to remove!\n");
     }
 
+    /* IO_LOCK_W is now unconditionally needed: at least for fdb upload */
+    fprintf(stderr, "lk_karma_request_io_lock (W): %s\n", 
+            CHECK(lk_karma_request_io_lock(karma,IO_LOCK_W)));
+    if(lk_synchronize_necessary(karma)){
+        lk_karma_get_all_file_details(karma, &psw);
+        lk_properties_import(psw);
+        free(psw);
+    }
     if(optind < argc){
-        fprintf(stderr, "lk_karma_request_io_lock: %s\n", 
-                CHECK(lk_karma_request_io_lock(karma,IO_LOCK_W)));
-        if(lk_synchronize_necessary(karma)){
-            lk_karma_get_all_file_details(karma, &psw);
-            lk_properties_import(psw);
-            free(psw);
-        }
         for(; optind<argc; optind++)
             ftw(argv[optind], treecopy, 1);
-    } else if (fdb) {
-        fprintf(stderr, "lk_karma_request_io_lock: %s\n", 
-                CHECK(lk_karma_request_io_lock(karma,IO_LOCK_W)));
-        if(lk_synchronize_necessary(karma)){
-            lk_karma_get_all_file_details(karma, &psw);
-            lk_properties_import(psw);
-            free(psw);
-        }
+    }
+    if (fdb) {
         fdb_upload(fdb);
     }
+/*  } else if (fdb) {
+        fdb_upload(fdb);
+    } */
 
     lk_properties_save();
     if (writeSmalldb) {
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
linux-karma-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-karma-devel

Reply via email to