summaryrefslogtreecommitdiffstats
path: root/module/plugins/hooks/ExtractArchive.py
diff options
context:
space:
mode:
Diffstat (limited to 'module/plugins/hooks/ExtractArchive.py')
-rw-r--r--module/plugins/hooks/ExtractArchive.py33
1 files changed, 19 insertions, 14 deletions
diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py
index 3d6df5b02..39da1ee7b 100644
--- a/module/plugins/hooks/ExtractArchive.py
+++ b/module/plugins/hooks/ExtractArchive.py
@@ -309,16 +309,18 @@ class ExtractArchive(Hook):
def reloadPasswords(self):
passwordfile = self.getConfig("passwordfile")
- if not exists(passwordfile):
- open(passwordfile, "wb").close()
-
- passwords = []
- f = open(passwordfile, "rb")
- for pw in f.read().splitlines():
- passwords.append(pw)
- f.close()
-
- self.passwords = passwords
+
+ try:
+ passwords = []
+ with open(passwordfile, "a+") as f:
+ for pw in f.read().splitlines():
+ passwords.append(pw)
+
+ except IOError, e:
+ self.logError(str(e))
+
+ else:
+ self.passwords = passwords
@Expose
@@ -328,12 +330,15 @@ class ExtractArchive(Hook):
if pw in self.passwords:
self.passwords.remove(pw)
+
self.passwords.insert(0, pw)
- f = open(passwordfile, "wb")
- for pw in self.passwords:
- f.write(pw + "\n")
- f.close()
+ try:
+ with open(passwordfile, "wb") as f:
+ for pw in self.passwords:
+ f.write(pw + "\n")
+ except IOError, e:
+ self.logError(str(e))
def setPermissions(self, files):