Skip to content

Commit

Permalink
fix possible stat call error in automatic update
Browse files Browse the repository at this point in the history
  • Loading branch information
DoTheEvo committed Feb 21, 2016
1 parent fdec88e commit 687c316
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions angrysearch_update_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
# CHECK IF NOTIFICATIONS CAN BE MADE
try:
from gi import require_version
require_version("Gtk", "3.0")
require_version("Notify", "0.7")
require_version('Gtk', '3.0')
require_version('Notify', '0.7')
from gi.repository import Notify, GdkPixbuf
NOTIFY_AVAILABLE = True
except ImportError:
Expand Down Expand Up @@ -148,15 +148,24 @@ def error(err):
for dname in dirs:
path = os.path.join(root, dname)
utf_path = path.decode(encoding='utf-8', errors='ignore')
stats = os.lstat(path)
epoch_time = stats.st_mtime.__trunc__()
try:
stats = os.lstat(path)
epoch_time = stats.st_mtime.__trunc__()
except:
print('Cant access: ' + str(path))
epoch_time = 0
dir_list.append(('1', utf_path, '', epoch_time))
for fname in files:
path = os.path.join(root, fname)
utf_path = path.decode(encoding='utf-8', errors='ignore')
stats = os.lstat(path)
size = stats.st_size
epoch_time = stats.st_mtime.__trunc__()
try:
stats = os.lstat(path)
size = stats.st_size
epoch_time = stats.st_mtime.__trunc__()
except:
print('Cant access: ' + str(path))
size = 0
epoch_time = 0
file_list.append(
('0', utf_path, size, epoch_time))

Expand Down Expand Up @@ -289,4 +298,10 @@ def open_database():
total_time = datetime.now() - START_TIME
noti_text = '{} | database updated'.format(
time_difference(total_time.seconds))
show_notification(noti_text)
try:
show_notification(noti_text)
except Exception as err:
print(err)
with open('/tmp/angrysearch_cron.log', 'a') as log:
t = '{:%Y-%b-%d | %H:%M | } '.format(datetime.now())
log.write(t + str(err) + '\n')

0 comments on commit 687c316

Please sign in to comment.