Skip to content

Commit 9477c7c

Browse files
committed
PIM-6080
Improve permission handling and path resolution logic in core commands This update refines permission error detection, adjusts path resolution to accommodate additional root cases, and improves response handling for task completion with warnings.
1 parent 05a5ac2 commit 9477c7c

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

cterasdk/cio/core/commands.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ def _raise_strict_permission_denied(result, path):
3636
if isinstance(result, str) and not result.strip():
3737
raise exceptions.io.core.PrivilegeError(path)
3838

39+
if isinstance(result, str):
40+
if _is_permission_denied_message(result):
41+
raise exceptions.io.core.PrivilegeError(path)
42+
return
43+
3944
msg = getattr(result, 'msg', None)
4045
rc = getattr(result, 'rc', None)
4146
if msg and _is_permission_denied_message(msg):
@@ -641,7 +646,17 @@ def _before_command(self):
641646
def _parents_generator(self):
642647
if self.parents:
643648
parts = self.path.parts
644-
for i in range(1, len(parts)):
649+
start_index = 1
650+
known_roots = ('My Files', 'Shared With Me', 'Shared', 'Team Portal')
651+
if parts:
652+
if parts[0] in known_roots:
653+
start_index = 2
654+
elif parts[0] in ('Users', 'Groups') and len(parts) > 1:
655+
if len(parts) > 2 and parts[2] in known_roots:
656+
start_index = 4
657+
else:
658+
start_index = 3
659+
for i in range(start_index, len(parts)):
645660
yield automatic_resolution('/'.join(parts[:i]), self._receiver.context)
646661
else:
647662
yield self.path
@@ -683,10 +698,10 @@ def _suppress_file_conflict_error(e):
683698

684699
def _handle_response(self, r):
685700
path = self.path.relative
686-
if self._strict_permission:
687-
_raise_strict_permission_denied(r, path)
688701
if r is None or r == 'Ok':
689702
return path
703+
if self._strict_permission:
704+
_raise_strict_permission_denied(r, path)
690705

691706
error, cause = exceptions.io.core.CreateDirectoryError(path), None
692707
if r == ResourceError.FileWithTheSameNameExist:
@@ -990,6 +1005,9 @@ def _handle_response(self, r):
9901005
if r.completed:
9911006
return self._task_complete(r)
9921007

1008+
if r.completed_with_warnings:
1009+
return r
1010+
9931011
if r.failed or r.completed_with_warnings:
9941012
return self._task_error(r)
9951013

0 commit comments

Comments
 (0)