mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-08 09:28:41 +00:00
Added error handling for inaccessible directories
This commit is contained in:
parent
567f4e5c3d
commit
8dfc405c3e
1 changed files with 29 additions and 9 deletions
|
@ -46,7 +46,7 @@ import base64
|
||||||
from deluge.ui.sessionproxy import SessionProxy
|
from deluge.ui.sessionproxy import SessionProxy
|
||||||
|
|
||||||
from input_popup import InputPopup
|
from input_popup import InputPopup
|
||||||
from popup import Popup
|
from popup import Popup, MessagePopup
|
||||||
import deluge.ui.console.colors as colors
|
import deluge.ui.console.colors as colors
|
||||||
import format_utils
|
import format_utils
|
||||||
|
|
||||||
|
@ -138,6 +138,10 @@ class AddTorrents(BaseMode, component.Component):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def __refresh_listing(self):
|
def __refresh_listing(self):
|
||||||
|
path = os.path.join(*self.path_stack[:self.path_stack_pos])
|
||||||
|
|
||||||
|
listing = os.listdir(path)
|
||||||
|
|
||||||
self.listing_files = []
|
self.listing_files = []
|
||||||
self.listing_dirs = []
|
self.listing_dirs = []
|
||||||
|
|
||||||
|
@ -146,9 +150,6 @@ class AddTorrents(BaseMode, component.Component):
|
||||||
self.raw_rows_dirs = []
|
self.raw_rows_dirs = []
|
||||||
self.formatted_rows = []
|
self.formatted_rows = []
|
||||||
|
|
||||||
path = os.path.join(*self.path_stack[:self.path_stack_pos])
|
|
||||||
|
|
||||||
listing = os.listdir(path)
|
|
||||||
for f in listing:
|
for f in listing:
|
||||||
if os.path.isdir(os.path.join(path, f)):
|
if os.path.isdir(os.path.join(path, f)):
|
||||||
if self.console_config["addtorrents_show_hidden_folders"]:
|
if self.console_config["addtorrents_show_hidden_folders"]:
|
||||||
|
@ -167,7 +168,7 @@ class AddTorrents(BaseMode, component.Component):
|
||||||
try:
|
try:
|
||||||
size = len(os.listdir(full_path))
|
size = len(os.listdir(full_path))
|
||||||
except:
|
except:
|
||||||
size = 0
|
size = -1
|
||||||
time = os.stat(full_path).st_mtime
|
time = os.stat(full_path).st_mtime
|
||||||
|
|
||||||
row = [dirname, size, time, full_path, 1]
|
row = [dirname, size, time, full_path, 1]
|
||||||
|
@ -222,7 +223,11 @@ class AddTorrents(BaseMode, component.Component):
|
||||||
time = row[2]
|
time = row[2]
|
||||||
|
|
||||||
if row[4]:
|
if row[4]:
|
||||||
cols = [filename.decode("utf8"), "%i items" % size, common.fdate(time)]
|
if size != -1:
|
||||||
|
size_str = "%i items" % size
|
||||||
|
else:
|
||||||
|
size_str = " unknown"
|
||||||
|
cols = [filename.decode("utf8"), size_str, common.fdate(time)]
|
||||||
widths = [self.cols - 35, 12, 23]
|
widths = [self.cols - 35, 12, 23]
|
||||||
self.formatted_rows.append(format_utils.format_row(cols, widths))
|
self.formatted_rows.append(format_utils.format_row(cols, widths))
|
||||||
else:
|
else:
|
||||||
|
@ -344,10 +349,17 @@ class AddTorrents(BaseMode, component.Component):
|
||||||
#It's a folder
|
#It's a folder
|
||||||
color_string = ""
|
color_string = ""
|
||||||
if self.raw_rows[i][4]:
|
if self.raw_rows[i][4]:
|
||||||
|
if self.raw_rows[i][1] == -1:
|
||||||
|
if i == self.cursel:
|
||||||
|
color_string = "{!black,red,bold!}"
|
||||||
|
else:
|
||||||
|
color_string = "{!red,black!}"
|
||||||
|
else:
|
||||||
if i == self.cursel:
|
if i == self.cursel:
|
||||||
color_string = "{!black,cyan,bold!}"
|
color_string = "{!black,cyan,bold!}"
|
||||||
else:
|
else:
|
||||||
color_string = "{!cyan,black!}"
|
color_string = "{!cyan,black!}"
|
||||||
|
|
||||||
elif i == self.cursel:
|
elif i == self.cursel:
|
||||||
if self.raw_rows[i][0] in self.marked:
|
if self.raw_rows[i][0] in self.marked:
|
||||||
color_string = "{!blue,white,bold!}"
|
color_string = "{!blue,white,bold!}"
|
||||||
|
@ -397,6 +409,14 @@ class AddTorrents(BaseMode, component.Component):
|
||||||
self.path_stack = self.path_stack[:self.path_stack_pos]
|
self.path_stack = self.path_stack[:self.path_stack_pos]
|
||||||
self.path_stack.append(dirname)
|
self.path_stack.append(dirname)
|
||||||
|
|
||||||
|
path = os.path.join(*self.path_stack[:self.path_stack_pos+1])
|
||||||
|
|
||||||
|
if not os.access(path, os.R_OK):
|
||||||
|
self.path_stack = self.path_stack[:self.path_stack_pos]
|
||||||
|
self.popup = MessagePopup(self, "Error", "{!error!}Access denied: %s" % path)
|
||||||
|
self.__refresh_listing()
|
||||||
|
return
|
||||||
|
|
||||||
self.path_stack_pos += 1
|
self.path_stack_pos += 1
|
||||||
|
|
||||||
self.view_offset = 0
|
self.view_offset = 0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue