erase /hdd/epg.dat after read
[enigma2.git] / lib / dvb / epgcache.cpp
index c412fd595381d51cb07d17f8b3c5fc66d354ae82..acdc9a9d1ae4ef6c979208e73ce64a8bbfe2ea77 100644 (file)
@@ -46,7 +46,6 @@ const eServiceReference &handleGroup(const eServiceReference &ref)
        return ref;
 }
 
-
 eventData::eventData(const eit_event_struct* e, int size, int type)
        :ByteSize(size&0xFF), type(type&0xFF)
 {
@@ -227,7 +226,11 @@ eEPGCache::eEPGCache()
        if (!res_mgr)
                eDebug("[eEPGCache] no resource manager !!!!!!!");
        else
+       {
                res_mgr->connectChannelAdded(slot(*this,&eEPGCache::DVBChannelAdded), m_chanAddedConn);
+               if (eDVBLocalTimeHandler::getInstance()->ready())
+                       timeUpdated();
+       }
        instance=this;
 }
 
@@ -564,29 +567,25 @@ void eEPGCache::sectionRead(const __u8 *data, int source, channel_data *channel)
 #endif
                        if (ev_erase_count > 0 && tm_erase_count > 0) // 2 different pairs have been removed
                        {
-                               eventData *tmp1 = ev_it->second,
-                                               *tmp2 = tm_it->second;
+                               // exempt memory
+                               delete ev_it->second;
+                               delete tm_it->second;
                                ev_it->second=evt;
                                tm_it->second=evt;
-                               // exempt memory
-                               delete tmp1;
-                               delete tmp2;
                        }
                        else if (ev_erase_count == 0 && tm_erase_count > 0)
                        {
-                               eventData *tmp = ev_it->second;
+                               // exempt memory
+                               delete ev_it->second;
                                tm_it=prevTimeIt=servicemap.second.insert( prevTimeIt, std::pair<const time_t, eventData*>( TM, evt ) );
                                ev_it->second=evt;
-                               // exempt memory
-                               delete tmp;
                        }
                        else if (ev_erase_count > 0 && tm_erase_count == 0)
                        {
-                               eventData *tmp = tm_it->second;
+                               // exempt memory
+                               delete tm_it->second;
                                ev_it=prevEventIt=servicemap.first.insert( prevEventIt, std::pair<const __u16, eventData*>( event_id, evt) );
                                tm_it->second=evt;
-                               // exempt memory
-                               delete tmp;
                        }
                        else // added new eventData
                        {
@@ -862,8 +861,9 @@ void eEPGCache::thread()
 
 void eEPGCache::load()
 {
-       singleLock s(cache_lock);
-       FILE *f = fopen("/hdd/epg.dat", "r");
+       unlink("/hdd/epg.dat.$$$");
+       rename("/hdd/epg.dat", "/hdd/epg.dat.$$$");
+       FILE *f = fopen("/hdd/epg.dat.$$$", "r");
        if (f)
        {
                int size=0;
@@ -893,12 +893,14 @@ void eEPGCache::load()
                        {
                                eDebug("[EPGC] epg file has incorrect byte order.. dont read it");
                                fclose(f);
+                               unlink("/hdd/epg.dat.$$$");
                                return;
                        }
                        char text1[13];
                        fread( text1, 13, 1, f);
                        if ( !strncmp( text1, "ENIGMA_EPG_V7", 13) )
                        {
+                               singleLock s(cache_lock);
                                fread( &size, sizeof(int), 1, f);
                                while(size--)
                                {
@@ -970,6 +972,7 @@ void eEPGCache::load()
                        fclose(f);
                }
        }
+       unlink("/hdd/epg.dat.$$$");
 }
 
 void eEPGCache::save()