Changeset baa177


Ignore:
Timestamp:
11/05/2009 03:44:46 AM (15 years ago)
Author:
Andrew Resch <andrewresch@gmail.com>
Branches:
2.0.x, develop, extjs4-port, master
Children:
0a84bc
Parents:
fa5b7e
Message:

Fix deleting old .fastresume files with fresh configs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • deluge/core/torrentmanager.py

    rfa5b7e rbaa177  
    136136        if not os.path.exists(os.path.join(get_config_dir(), "state")):
    137137            os.makedirs(os.path.join(get_config_dir(), "state"))
    138            
     138
    139139        # Create the torrents dict { torrent_id: Torrent }
    140140        self.torrents = {}
     
    147147        # self.num_resume_data used to save resume_data in bulk
    148148        self.num_resume_data = 0
    149        
     149
    150150        # Keeps track of resume data that needs to be saved to disk
    151151        self.resume_data = {}
     
    217217        self.save_state()
    218218
    219         # Make another list just to make sure all paused torrents will be 
    220         # passed to self.save_resume_data(). With 
     219        # Make another list just to make sure all paused torrents will be
     220        # passed to self.save_resume_data(). With
    221221        # self.shutdown_torrent_pause_list it is possible to have a case when
    222222        # torrent_id is removed from it in self.on_alert_torrent_paused()
     
    230230                self.shutdown_torrent_pause_list.append(key)
    231231                save_resume_data_list.append(key)
    232                
     232
    233233        self.save_resume_data(save_resume_data_list)
    234        
     234
    235235        # We have to wait for all torrents to pause and write their resume data
    236236        wait = True
     
    299299    def legacy_delete_resume_data(self, torrent_id):
    300300        """Deletes the .fastresume file"""
    301         path = os.path.join(self.config["state_location"],
     301        path = os.path.join(get_config_dir(), "state",
    302302                            torrent_id + ".fastresume")
    303303        log.debug("Deleting fastresume file: %s", path)
     
    365365                resume_data = self.legacy_get_resume_data_from_file(state.torrent_id)
    366366                self.legacy_delete_resume_data(state.torrent_id)
    367                    
     367
    368368            add_torrent_params["resume_data"] = resume_data
    369369        else:
     
    522522            log.warning("Error removing torrent: %s", e)
    523523            return False
    524        
     524
    525525        # Remove fastresume data if it is exists
    526526        resume_data = self.load_resume_data_file()
     
    623623        try:
    624624            log.debug("Saving torrent state file.")
    625             state_file = open(os.path.join(get_config_dir(), 
     625            state_file = open(os.path.join(get_config_dir(),
    626626                              "state", "torrents.state.new"), "wb")
    627627            cPickle.dump(state, state_file)
     
    650650        torrent_ids is None
    651651        """
    652        
     652
    653653        if torrent_ids is None:
    654654            torrent_ids = self.torrents.keys()
    655  
     655
    656656        for torrent_id in torrent_ids:
    657657            self.torrents[torrent_id].save_resume_data()
    658            
     658
    659659        self.num_resume_data = len(torrent_ids)
    660660
     
    669669        except (EOFError, IOError, Exception), e:
    670670            log.warning("Unable to load fastresume file: %s", e)
    671    
     671
    672672        # If the libtorrent bdecode doesn't happen properly, it will return None
    673673        # so we need to make sure we return a {}
    674674        if resume_data is None:
    675675            return {}
    676            
     676
    677677        return resume_data
    678        
     678
    679679    def save_resume_data_file(self, resume_data=None):
    680680        """
     
    683683        disk, else, we update `resume_data` with self.resume_data and save
    684684        that to disk.
    685        
     685
    686686        :param resume_data: the current resume_data, this will be loaded from disk if not provided
    687687        :type resume_data: dict
    688        
     688
    689689        """
    690690        # Check to see if we're waiting on more resume data
    691691        if self.num_resume_data or not self.resume_data:
    692692            return
    693            
     693
    694694        path = os.path.join(get_config_dir(), "state", "torrents.fastresume")
    695        
     695
    696696        # First step is to load the existing file and update the dictionary
    697697        if resume_data is None:
    698698            resume_data = self.load_resume_data_file()
    699    
     699
    700700        resume_data.update(self.resume_data)
    701701        self.resume_data = {}
     
    787787                if torrent.options["download_location"] != move_path:
    788788                    torrent.move_storage(move_path)
    789                    
     789
    790790            torrent.is_finished = True
    791791            component.get("EventManager").emit(TorrentFinishedEvent(torrent_id))
    792792
    793793        torrent.update_state()
    794        
     794
    795795        # Only save resume data if it was actually downloaded something. Helps
    796796        # on startup with big queues with lots of seeding torrents. Libtorrent
     
    918918    def on_alert_save_resume_data(self, alert):
    919919        log.debug("on_alert_save_resume_data")
    920        
     920
    921921        torrent_id = str(alert.handle.info_hash())
    922        
     922
    923923        try:
    924924            torrent = self.torrents[torrent_id]
     
    929929        self.resume_data[torrent_id] = lt.bencode(alert.resume_data)
    930930        self.num_resume_data -= 1
    931        
     931
    932932        torrent.waiting_on_resume_data = False
    933        
     933
    934934        self.save_resume_data_file()
    935935
     
    940940        except:
    941941            return
    942            
     942
    943943        self.num_resume_data -= 1
    944944        torrent.waiting_on_resume_data = False
    945        
     945
    946946        self.save_resume_data_file()
    947            
     947
    948948
    949949    def on_alert_file_renamed(self, alert):
Note: See TracChangeset for help on using the changeset viewer.