Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NAS-112721 / 21.10 / Add API call to create directories #7645

Merged
merged 4 commits into from Oct 7, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/middlewared/middlewared/plugins/filesystem.py
Expand Up @@ -43,6 +43,56 @@ def resolve_cluster_path(self, path, ignore_ctdb=False):
cluster_path = path.replace(FuseConfig.FUSE_PATH_SUBST.value, f'{FuseConfig.FUSE_PATH_BASE.value}/')
return cluster_path

@accepts(Str('path'))
@returns(Dict(
'path_entry',
Str('name', required=True),
Path('path', required=True),
Path('realpath', required=True),
Str('type', required=True, enum=['DIRECTORY', 'FILESYSTEM', 'SYMLINK', 'OTHER']),
Int('size', required=True, null=True),
Int('mode', required=True, null=True),
Bool('acl', required=True, null=True),
Int('uid', required=True, null=True),
Int('gid', required=True, null=True),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why null=True, can these be null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy-paste. I'll just change to Ref the path_entry from filesystem.listdir, which was the intention to begin with.

))
def mkdir(self, path):
"""
Create a directory at the specified path.
"""
path = self.resolve_cluster_path(path)
is_clustered = path.startswith("/cluster")

p = pathlib.Path(path)
if not p.is_absolute():
raise CallError(f'{path}: not an absolute path.', errno.EINVAL)

if p.exists():
raise CallError(f'{path}: path already exists.', errno.EEXIST)

realpath = os.path.realpath(path)
if not is_clustered and not realpath.startswith('/mnt/'):
raise CallError(f'{path}: path not permitted', errno.EPERM)

os.mkdir(path)
data = {
'name': p.parts[-1],
'path': path,
'realpath': realpath,
'type': 'DIRECTORY',
}

stat = p.stat()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move this call just below mkdir and have data in a single dictionary declaration

data.update({
'size': stat.st_size,
'mode': stat.st_mode,
'acl': False if self.acl_is_trivial(data["path"]) else True,
'uid': stat.st_uid,
'gid': stat.st_gid,
})

return data

@accepts(Str('path', required=True), Ref('query-filters'), Ref('query-options'))
@filterable_returns(Dict(
'path_entry',
Expand Down