Skip to content

Commit

Permalink
optimize Sftp._mkdir, fixes #80
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasWaldmann committed Oct 15, 2024
1 parent 96a017e commit aa920d7
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/borgstore/backends/sftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,16 @@ def close(self):
def _mkdir(self, name, *, parents=False, exist_ok=False):
# Path.mkdir, but via sftp
p = Path(name)
if parents:
for parent in reversed(p.parents):
try:
self.client.mkdir(str(parent))
except OSError:
# maybe already existed?
pass
try:
self.client.mkdir(str(p))
except FileNotFoundError:
raise # parents == False and the parent dir is missing.
# the parent dir is missing
if not parents:
raise
# first create parent dir(s), recursively:
self._mkdir(p.parents[0], parents=parents, exist_ok=exist_ok)
# then retry:
self.client.mkdir(str(p))
except OSError:
# maybe p already existed?
if not exist_ok:
Expand Down

0 comments on commit aa920d7

Please sign in to comment.