Skip to content

Commit

Permalink
Cleanup and simplify directory tree creations
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrimesix committed Apr 26, 2024
1 parent 49d096f commit 9dc8522
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions src/middlewared/middlewared/plugins/nfs.py
Expand Up @@ -155,27 +155,11 @@ def setup_directories(self):
gid = self.name_to_id_conversion(i.owner()['gid'], name_type='group')
path = i.path()
if i.is_dir():
open_flags = os.O_RDWR | os.O_DIRECTORY
os.makedirs(path, exist_ok=True)
else:
open_flags = os.O_RDWR

try:
with open(os.open(path, flags=open_flags)) as f:
os.fchmod(f.fileno(), i.mode())
os.fchown(f.fileno(), uid, gid)
except IsADirectoryError:
if not i.is_dir():
# the path is expected to be a file but it's a directory
self.logger.error('Expected %r to be a file but instead found a directory', path)
else:
self.logger.error('Unexpected failure updating file %r', path, exc_info=True)
except NotADirectoryError:
if i.is_dir():
# the path is expected to be a directory but it's a file
self.logger.error('Expected %r to be a directory but instead found a file', path)
else:
self.logger.error('Unexpected failure updating directory %r', path, exc_info=True)
os.chmod(path, i.mode())
os.chown(path, uid, gid)
except Exception:
self.logger.error('Unexpected failure initializing %r', path, exc_info=True)

Expand Down

0 comments on commit 9dc8522

Please sign in to comment.