Changeset 1097

Show
Ignore:
Timestamp:
2008-09-15 06:27:46 (4 months ago)
Author:
MaierMan
Message:

Remove broken downloads from queuefile

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/chrome/content/dta/manager.js

    r1092 r1097  
    18491849                        e.hashType = Utils.atos(this.hash.type); 
    18501850                } 
    1851                 if (this.autoRetrying) { 
    1852                         e.state = QUEUED; 
    1853                 } 
    1854                 else if (this.is(RUNNING)) { 
     1851                if (this.autoRetrying || this.is(RUNNING)) { 
    18551852                        e.state = QUEUED; 
    18561853                } 
  • trunk/chrome/content/dta/manager/sessionmanager.js

    r1035 r1097  
    4444 
    4545var SessionManager = { 
     46        _broken: [], 
     47         
    4648        init: function() { 
    4749                this._con = Serv('@mozilla.org/storage/service;1', 'mozIStorageService') 
     
    194196                                        stmt.finalize(); 
    195197                                        delete stmt; 
     198                                        if (this._broken.length) { 
     199                                                try { 
     200                                                        for each (let id in this._broken) { 
     201                                                                this.deleteDownload(id); 
     202                                                                Debug.logString("Removed broken download #" + id); 
     203                                                        } 
     204                                                } 
     205                                                catch (ex) { 
     206                                                        Debug.log("failed to remove broken downloads", ex); 
     207                                                } 
     208                                                this._broken = []; 
     209                                        }                                        
    196210                                        delete this._loader; 
    197211                                        this.endUpdate(); 
     
    205219                                try { 
    206220                                        let dbId = stmt.getInt64(0); 
    207                                         let down = Serializer.decode(stmt.getUTF8String(1)); 
    208                                         let get = function(attr) { 
    209                                                 return (attr in down) ? down[attr] : null; 
     221                                        try { 
     222                                                let down = Serializer.decode(stmt.getUTF8String(1)); 
     223                                                 
     224                                                let get = function(attr) { 
     225                                                        return (attr in down) ? down[attr] : null; 
     226                                                } 
     227                 
     228                                                let d = new QueueItem(); 
     229                                                d.dbId = dbId; 
     230                                                d.urlManager = new UrlManager(down.urlManager); 
     231                                                d.numIstance = get("numIstance"); 
     232                 
     233                                                let referrer = get('referrer'); 
     234                                                if (referrer) { 
     235                                                        try { 
     236                                                                d.referrer = referrer.toURL(); 
     237                                                        } 
     238                                                        catch (ex) { 
     239                                                                // We might have been fed with about:blank or other crap. so ignore. 
     240                                                        } 
     241                                                } 
     242                                         
     243                                                // only access the setter of the last so that we don't generate stuff trice. 
     244                                                d._pathName = get('pathName'); 
     245                                                d._description = get('description'); 
     246                                                d._mask = get('mask'); 
     247                                                d.fileName = get('fileName'); 
     248                                                 
     249                                                let tmpFile = get('tmpFile'); 
     250                                                if (tmpFile) { 
     251                                                        try { 
     252                                                                tmpFile = new FileFactory(tmpFile); 
     253                                                                if (tmpFile.exists()) { 
     254                                                                        d._tmpFile = tmpFile; 
     255                                                                } 
     256                                                                else { 
     257                                                                        // Download partfile is gone! 
     258                                                                        // XXX find appropriate error message! 
     259                                                                        d.fail(_("accesserror"), _("permissions") + " " + _("destpath") + ". " + _("checkperm"), _("accesserror")); 
     260                                                                } 
     261                                                        } 
     262                                                        catch (ex) { 
     263                                                                Debug.log("tried to construct with invalid tmpFile", ex); 
     264                                                                d.cancel(); 
     265                                                        } 
     266                                                }                                
     267                 
     268                                                d.startDate = new Date(get("startDate")); 
     269                                                d.visitors = new VisitorManager(down.visitors); 
     270                                                 
     271                                                for each (let e in [ 
     272                                                        'contentType', 
     273                                                        'conflicts', 
     274                                                        'postData', 
     275                                                        'destinationName', 
     276                                                        'resumable', 
     277                                                        'totalSize', 
     278                                                        'compression', 
     279                                                        'fromMetalink', 
     280                                                ]) { 
     281                                                        d[e] = (e in down) ? down[e] : null; 
     282                                                } 
     283                 
     284                                                if (down.hash) { 
     285                                                        d.hash = new DTA_Hash(down.hash, down.hashType); 
     286                                                } 
     287                                                if ('maxChunks' in down) { 
     288                                                        d._maxChunks = down.maxChunks; 
     289                                                } 
     290                 
     291                                                d.started = d.partialSize != 0; 
     292                                                let state = get('state')  
     293                                                if (state) { 
     294                                                        d._state = state; 
     295                                                } 
     296                                                switch (d._state) { 
     297                                                        case PAUSED: 
     298                                                        case QUEUED: 
     299                                                        { 
     300                                                                for each (let c in down.chunks) { 
     301                                                                        d.chunks.push(new Chunk(d, c.start, c.end, c.written)); 
     302                                                                } 
     303                                                                d.refreshPartialSize(); 
     304                                                                if (d._state == PAUSED) { 
     305                                                                        d.status = TEXT_PAUSED; 
     306                                                                } 
     307                                                                else { 
     308                                                                        d.status = TEXT_QUEUED; 
     309                                                                } 
     310                                                        } 
     311                                                        break; 
     312                                                         
     313                                                        case COMPLETE: 
     314                                                                d.partialSize = d.totalSize; 
     315                                                                d.status = TEXT_COMPLETE; 
     316                                                        break; 
     317                                                         
     318                                                        case CANCELED: 
     319                                                                d.status = TEXT_CANCELED; 
     320                                                        break; 
     321                                                } 
     322                                                 
     323                                                // XXX better call this only once 
     324                                                // See above 
     325                                                d.rebuildDestination(); 
     326                 
     327                                                Tree.add(d); 
    210328                                        } 
    211          
    212                                         let d = new QueueItem(); 
    213                                         d.dbId = dbId; 
    214                                         d.urlManager = new UrlManager(down.urlManager); 
    215                                         d.numIstance = get("numIstance"); 
    216          
    217                                         let referrer = get('referrer'); 
    218                                         if (referrer) { 
    219                                                 try { 
    220                                                         d.referrer = referrer.toURL(); 
    221                                                 } 
    222                                                 catch (ex) { 
    223                                                         // We might have been fed with about:blank or other crap. so ignore. 
    224                                                 } 
     329                                        catch (ex) { 
     330                                                Debug.log('failed to init download #' + dbId + ' from queuefile', ex); 
     331                                                this._broken.push(dbId); 
    225332                                        } 
    226                                  
    227                                         // only access the setter of the last so that we don't generate stuff trice. 
    228                                         d._pathName = get('pathName'); 
    229                                         d._description = get('description'); 
    230                                         d._mask = get('mask'); 
    231                                         d.fileName = get('fileName'); 
    232                                          
    233                                         let tmpFile = get('tmpFile'); 
    234                                         if (tmpFile) { 
    235                                                 try { 
    236                                                         tmpFile = new FileFactory(tmpFile); 
    237                                                         if (tmpFile.exists()) { 
    238                                                                 d._tmpFile = tmpFile; 
    239                                                         } 
    240                                                         else { 
    241                                                                 // Download partfile is gone! 
    242                                                                 // XXX find appropriate error message! 
    243                                                                 d.fail(_("accesserror"), _("permissions") + " " + _("destpath") + ". " + _("checkperm"), _("accesserror")); 
    244                                                         } 
    245                                                 } 
    246                                                 catch (ex) { 
    247                                                         Debug.log("tried to construct with invalid tmpFile", ex); 
    248                                                         d.cancel(); 
    249                                                 } 
    250                                         }                                
    251          
    252                                         d.startDate = new Date(get("startDate")); 
    253                                         d.visitors = new VisitorManager(down.visitors); 
    254                                          
    255                                         for each (let e in [ 
    256                                                 'contentType', 
    257                                                 'conflicts', 
    258                                                 'postData', 
    259                                                 'destinationName', 
    260                                                 'resumable', 
    261                                                 'totalSize', 
    262                                                 'compression', 
    263                                                 'fromMetalink', 
    264                                         ]) { 
    265                                                 d[e] = (e in down) ? down[e] : null; 
    266                                         } 
    267          
    268                                         if (down.hash) { 
    269                                                 d.hash = new DTA_Hash(down.hash, down.hashType); 
    270                                         } 
    271                                         if ('maxChunks' in down) { 
    272                                                 d._maxChunks = down.maxChunks; 
    273                                         } 
    274          
    275                                         d.started = d.partialSize != 0; 
    276                                         let state = get('state')  
    277                                         if (state) { 
    278                                                 d._state = state; 
    279                                         } 
    280                                         switch (d._state) { 
    281                                                 case PAUSED: 
    282                                                 case QUEUED: 
    283                                                 { 
    284                                                         for each (let c in down.chunks) { 
    285                                                                 d.chunks.push(new Chunk(d, c.start, c.end, c.written)); 
    286                                                         } 
    287                                                         d.refreshPartialSize(); 
    288                                                         if (d._state == PAUSED) { 
    289                                                                 d.status = TEXT_PAUSED; 
    290                                                         } 
    291                                                         else { 
    292                                                                 d.status = TEXT_QUEUED; 
    293                                                         } 
    294                                                 } 
    295                                                 break; 
    296                                                  
    297                                                 case COMPLETE: 
    298                                                         d.partialSize = d.totalSize; 
    299                                                         d.status = TEXT_COMPLETE; 
    300                                                 break; 
    301                                                  
    302                                                 case CANCELED: 
    303                                                         d.status = TEXT_CANCELED; 
    304                                                 break; 
    305                                         } 
    306                                          
    307                                         // XXX better call this only once 
    308                                         // See above 
    309                                         d.rebuildDestination(); 
    310          
    311                                         Tree.add(d); 
    312333                                } 
    313334                                catch (ex) {