Changeset baa177
- Timestamp:
- 11/05/2009 03:44:46 AM (15 years ago)
- Branches:
- 2.0.x, develop, extjs4-port, master
- Children:
- 0a84bc
- Parents:
- fa5b7e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
deluge/core/torrentmanager.py
rfa5b7e rbaa177 136 136 if not os.path.exists(os.path.join(get_config_dir(), "state")): 137 137 os.makedirs(os.path.join(get_config_dir(), "state")) 138 138 139 139 # Create the torrents dict { torrent_id: Torrent } 140 140 self.torrents = {} … … 147 147 # self.num_resume_data used to save resume_data in bulk 148 148 self.num_resume_data = 0 149 149 150 150 # Keeps track of resume data that needs to be saved to disk 151 151 self.resume_data = {} … … 217 217 self.save_state() 218 218 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 221 221 # self.shutdown_torrent_pause_list it is possible to have a case when 222 222 # torrent_id is removed from it in self.on_alert_torrent_paused() … … 230 230 self.shutdown_torrent_pause_list.append(key) 231 231 save_resume_data_list.append(key) 232 232 233 233 self.save_resume_data(save_resume_data_list) 234 234 235 235 # We have to wait for all torrents to pause and write their resume data 236 236 wait = True … … 299 299 def legacy_delete_resume_data(self, torrent_id): 300 300 """Deletes the .fastresume file""" 301 path = os.path.join( self.config["state_location"],301 path = os.path.join(get_config_dir(), "state", 302 302 torrent_id + ".fastresume") 303 303 log.debug("Deleting fastresume file: %s", path) … … 365 365 resume_data = self.legacy_get_resume_data_from_file(state.torrent_id) 366 366 self.legacy_delete_resume_data(state.torrent_id) 367 367 368 368 add_torrent_params["resume_data"] = resume_data 369 369 else: … … 522 522 log.warning("Error removing torrent: %s", e) 523 523 return False 524 524 525 525 # Remove fastresume data if it is exists 526 526 resume_data = self.load_resume_data_file() … … 623 623 try: 624 624 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(), 626 626 "state", "torrents.state.new"), "wb") 627 627 cPickle.dump(state, state_file) … … 650 650 torrent_ids is None 651 651 """ 652 652 653 653 if torrent_ids is None: 654 654 torrent_ids = self.torrents.keys() 655 655 656 656 for torrent_id in torrent_ids: 657 657 self.torrents[torrent_id].save_resume_data() 658 658 659 659 self.num_resume_data = len(torrent_ids) 660 660 … … 669 669 except (EOFError, IOError, Exception), e: 670 670 log.warning("Unable to load fastresume file: %s", e) 671 671 672 672 # If the libtorrent bdecode doesn't happen properly, it will return None 673 673 # so we need to make sure we return a {} 674 674 if resume_data is None: 675 675 return {} 676 676 677 677 return resume_data 678 678 679 679 def save_resume_data_file(self, resume_data=None): 680 680 """ … … 683 683 disk, else, we update `resume_data` with self.resume_data and save 684 684 that to disk. 685 685 686 686 :param resume_data: the current resume_data, this will be loaded from disk if not provided 687 687 :type resume_data: dict 688 688 689 689 """ 690 690 # Check to see if we're waiting on more resume data 691 691 if self.num_resume_data or not self.resume_data: 692 692 return 693 693 694 694 path = os.path.join(get_config_dir(), "state", "torrents.fastresume") 695 695 696 696 # First step is to load the existing file and update the dictionary 697 697 if resume_data is None: 698 698 resume_data = self.load_resume_data_file() 699 699 700 700 resume_data.update(self.resume_data) 701 701 self.resume_data = {} … … 787 787 if torrent.options["download_location"] != move_path: 788 788 torrent.move_storage(move_path) 789 789 790 790 torrent.is_finished = True 791 791 component.get("EventManager").emit(TorrentFinishedEvent(torrent_id)) 792 792 793 793 torrent.update_state() 794 794 795 795 # Only save resume data if it was actually downloaded something. Helps 796 796 # on startup with big queues with lots of seeding torrents. Libtorrent … … 918 918 def on_alert_save_resume_data(self, alert): 919 919 log.debug("on_alert_save_resume_data") 920 920 921 921 torrent_id = str(alert.handle.info_hash()) 922 922 923 923 try: 924 924 torrent = self.torrents[torrent_id] … … 929 929 self.resume_data[torrent_id] = lt.bencode(alert.resume_data) 930 930 self.num_resume_data -= 1 931 931 932 932 torrent.waiting_on_resume_data = False 933 933 934 934 self.save_resume_data_file() 935 935 … … 940 940 except: 941 941 return 942 942 943 943 self.num_resume_data -= 1 944 944 torrent.waiting_on_resume_data = False 945 945 946 946 self.save_resume_data_file() 947 947 948 948 949 949 def on_alert_file_renamed(self, alert):
Note:
See TracChangeset
for help on using the changeset viewer.