|
@@ -188,6 +188,11 @@ class Repository:
|
|
|
|
|
|
exit_mcode = 20
|
|
|
|
|
|
+ class PathPermissionDenied(Error):
|
|
|
+ """Permission denied to {}."""
|
|
|
+
|
|
|
+ exit_mcode = 21
|
|
|
+
|
|
|
def __init__(
|
|
|
self,
|
|
|
path,
|
|
@@ -299,13 +304,23 @@ class Repository:
|
|
|
st = os.stat(path)
|
|
|
except FileNotFoundError:
|
|
|
pass # nothing there!
|
|
|
+ except PermissionError:
|
|
|
+ raise self.PathPermissionDenied(path) from None
|
|
|
else:
|
|
|
# there is something already there!
|
|
|
if self.is_repository(path):
|
|
|
raise self.AlreadyExists(path)
|
|
|
- if not stat.S_ISDIR(st.st_mode) or os.listdir(path):
|
|
|
+ if not stat.S_ISDIR(st.st_mode):
|
|
|
raise self.PathAlreadyExists(path)
|
|
|
- # an empty directory is acceptable for us.
|
|
|
+ try:
|
|
|
+ files = os.listdir(path)
|
|
|
+ except PermissionError:
|
|
|
+ raise self.PathPermissionDenied(path) from None
|
|
|
+ else:
|
|
|
+ if files: # a dir, but not empty
|
|
|
+ raise self.PathAlreadyExists(path)
|
|
|
+ else: # an empty directory is acceptable for us.
|
|
|
+ pass
|
|
|
|
|
|
while True:
|
|
|
# Check all parent directories for Borg's repository README
|