Module: deluge
Branch: master
Commit: 1e0005f572345de86bbbb6bc11df98958979a911

Author: Calum Lind <[email protected]>
Date:   Mon Feb 14 00:18:45 2011 +0000

Fix: os.join created root path in Remove_Empty_Folder if variable 'folder' had 
a leading slash

---

 deluge/core/torrentmanager.py |   17 ++++++++++-------
 1 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/deluge/core/torrentmanager.py b/deluge/core/torrentmanager.py
index 9e6b35d..4c57874 100644
--- a/deluge/core/torrentmanager.py
+++ b/deluge/core/torrentmanager.py
@@ -42,6 +42,7 @@ import time
 import shutil
 import operator
 import logging
+import re
 
 from twisted.internet import reactor
 from twisted.internet.task import LoopingCall
@@ -746,18 +747,20 @@ class TorrentManager(component.Component):
             fastresume_file.close()
         except IOError:
             log.warning("Error trying to save fastresume file")
-        
+
     def remove_empty_folders(self, torrent_id, folder):
         """
         Recursively removes folders but only if they are empty.
         Cleans up after libtorrent folder renames.
-            
+
         """
         if torrent_id not in self.torrents:
-            raise InvalidTorrentError("torrent_id is not in session")    
-          
+            raise InvalidTorrentError("torrent_id is not in session")
+
         info = self.torrents[torrent_id].get_status(['save_path'])
-        folder_full_path = os.path.join(info['save_path'], folder)
+        # Regex removes leading slashes that causes join function to ignore 
save_path
+        folder_full_path = os.path.join(info['save_path'], re.sub("^/*", "", 
folder))
+        folder_full_path = os.path.normpath(folder_full_path)
 
         try:
             if not os.listdir(folder_full_path):
@@ -775,7 +778,7 @@ class TorrentManager(component.Component):
                                 log.debug("%s", strerror)
 
         except OSError as (errno, strerror):
-            log.debug("Cannot Remove Folder: %s (ErrNo %s)", strerror, errno)  
  
+            log.debug("Cannot Remove Folder: %s (ErrNo %s)", strerror, errno)
 
     def queue_top(self, torrent_id):
         """Queue torrent to top"""
@@ -1038,7 +1041,7 @@ class TorrentManager(component.Component):
                 if len(wait_on_folder[2]) == 1:
                     # This is the last alert we were waiting for, time to send 
signal
                     
component.get("EventManager").emit(TorrentFolderRenamedEvent(torrent_id, 
wait_on_folder[0], wait_on_folder[1]))
-                    # Empty folders are removed after libtorrent folder 
renames 
+                    # Empty folders are removed after libtorrent folder renames
                     self.remove_empty_folders(torrent_id, wait_on_folder[0])
                     del torrent.waiting_on_folder_rename[i]
                     self.save_resume_data((torrent_id,))

-- 
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en.

Reply via email to