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
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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), | ||
)) | ||
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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can move this call just below |
||
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', | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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.